parquet_derive

Derive Macro ParquetRecordWriter

Source
#[derive(ParquetRecordWriter)]
Expand description

Derive flat, simple RecordWriter implementations.

Works by parsing a struct tagged with #[derive(ParquetRecordWriter)] and emitting the correct writing code for each field of the struct. Column writers are generated in the order they are defined.

It is up to the programmer to keep the order of the struct fields lined up with the schema.

Example:

use parquet_derive::ParquetRecordWriter;
use std::io::{self, Write};
use parquet::file::properties::WriterProperties;
use parquet::file::writer::SerializedFileWriter;
use parquet::record::RecordWriter;
use std::fs::File;

use std::sync::Arc;

#[derive(ParquetRecordWriter)]
struct ACompleteRecord<'a> {
  pub a_bool: bool,
  pub a_str: &'a str,
}

pub fn write_some_records() {
  let samples = vec![
    ACompleteRecord {
      a_bool: true,
      a_str: "I'm true"
    },
    ACompleteRecord {
      a_bool: false,
      a_str: "I'm false"
    }
  ];
 let file = File::open("some_file.parquet").unwrap();

 let schema = samples.as_slice().schema().unwrap();

 let mut writer = SerializedFileWriter::new(file, schema, Default::default()).unwrap();

 let mut row_group = writer.next_row_group().unwrap();
 samples.as_slice().write_to_row_group(&mut row_group).unwrap();
 row_group.close().unwrap();
 writer.close().unwrap();
}