66 releases (major breaking)

51.0.0 Mar 18, 2024
50.0.0 Jan 12, 2024
49.0.0 Nov 13, 2023
48.0.1 Nov 13, 2023
3.0.0 Jan 26, 2021

#1161 in Procedural macros

Download history 79/week @ 2023-12-21 155/week @ 2023-12-28 52/week @ 2024-01-04 57/week @ 2024-01-11 174/week @ 2024-01-18 214/week @ 2024-01-25 530/week @ 2024-02-01 266/week @ 2024-02-08 447/week @ 2024-02-15 777/week @ 2024-02-22 530/week @ 2024-02-29 743/week @ 2024-03-07 896/week @ 2024-03-14 336/week @ 2024-03-21 469/week @ 2024-03-28 733/week @ 2024-04-04

2,590 downloads per month
Used in xpq2

Apache-2.0

2.5MB
51K SLoC

Parquet Derive

A crate for deriving RecordWriter and RecordReader for arbitrary, simple structs. This does not generate readers or writers for arbitrarily nested structures. It only works for primitives and a few generic structures and various levels of reference. Please see features checklist for what is currently supported.

Derive also has some support for the chrono time library. You must must enable the chrono feature to get this support.

Usage

Add this to your Cargo.toml:

[dependencies]
parquet = "39.0.0"
parquet_derive = "39.0.0"

and this to your crate root:

extern crate parquet;
#[macro_use] extern crate parquet_derive;

Example usage of deriving a RecordWriter for your struct:

use parquet;
use parquet::record::RecordWriter;

#[derive(ParquetRecordWriter)]
struct ACompleteRecord<'a> {
    pub a_bool: bool,
    pub a_str: &'a str,
    pub a_string: String,
    pub a_borrowed_string: &'a String,
    pub maybe_a_str: Option<&'a str>,
    pub magic_number: i32,
    pub low_quality_pi: f32,
    pub high_quality_pi: f64,
    pub maybe_pi: Option<f32>,
    pub maybe_best_pi: Option<f64>,
}

// Initialize your parquet file
let mut writer = SerializedFileWriter::new(file, schema, props).unwrap();
let mut row_group = writer.next_row_group().unwrap();

// Build up your records
let chunks = vec![ACompleteRecord{...}];

// The derived `RecordWriter` takes over here
(&chunks[..]).write_to_row_group(&mut row_group);

writer.close_row_group(row_group).unwrap();
writer.close().unwrap();

Example usage of deriving a RecordReader for your struct:

use parquet::file::{serialized_reader::SerializedFileReader, reader::FileReader};
use parquet_derive::ParquetRecordReader;

#[derive(ParquetRecordReader)]
struct ACompleteRecord {
    pub a_bool: bool,
    pub a_string: String,
    pub i16: i16,
    pub i32: i32,
    pub u64: u64,
    pub isize: isize,
    pub float: f32,
    pub double: f64,
    pub now: chrono::NaiveDateTime,
    pub byte_vec: Vec<u8>,
}

// Initialize your parquet file
let reader = SerializedFileReader::new(file).unwrap();
let mut row_group = reader.get_row_group(0).unwrap();

// create your records vector to read into
let mut chunks: Vec<ACompleteRecord> = Vec::new();

// The derived `RecordReader` takes over here
chunks.read_from_row_group(&mut *row_group, 1).unwrap();

Features

  • Support writing String, &str, bool, i32, f32, f64, Vec<u8>

  • Support writing dictionaries

  • Support writing logical types like timestamp

  • Derive definition_levels for Option for writing

  • Derive definition levels for nested structures for writing

  • Derive writing tuple struct

  • Derive writing tuple container types

  • Support reading String, &str, bool, i32, f32, f64, Vec<u8>

  • Support reading/writing dictionaries

  • Support reading/writing logical types like timestamp

  • Handle definition_levels for Option for reading

  • Handle definition levels for nested structures for reading

  • Derive reading/writing tuple struct

  • Derive reading/writing tuple container types

Requirements

  • Same as parquet-rs

Test

Testing a *_derive crate requires an intermediate crate. Go to parquet_derive_test and run cargo test for unit tests.

Docs

To build documentation, run cargo doc --no-deps. To compile and view in the browser, run cargo doc --no-deps --open.

License

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0.

Dependencies

~4–11MB
~98K SLoC