packages

table::parquet

On this page

Parquet files, read and written without a Parquet library. Writing: flat optional columns (i64 INT64, f64 DOUBLE, bool BOOLEAN, str and cat BYTE_ARRAY strings, dictionary-encoded for cat and for str with few distinct values, date DATE, datetime TIMESTAMP(NANOS)), data pages v1, min / max statistics, Snappy or no compression, and the Arrow schema in the metadata. Reading: data pages v1 and v2; PLAIN, dictionary, RLE, DELTA_BINARY_PACKED, DELTA_LENGTH_BYTE_ARRAY, DELTA_BYTE_ARRAY and BYTE_STREAM_SPLIT encodings; Snappy, Zstandard or no compression; INT32 / INT64 of any integer logical type, INT96 and every timestamp unit, FLOAT, DOUBLE, FLOAT16, strings. Nested, decimal, time and fixed-length binary columns are an error naming the column, unless columns leaves them out; gzip, Brotli and LZ4 pages are an error.

Structs

ParquetSource

pub struct Parquet

How to read or write Parquet. Start from Parquet::new().

nabi
use table::Parquet;
let t = table::table!{ "city": ["Seoul", "Busan", none], "temp": [21.5, 24.0, 19.0] };
let b = Parquet::new().write_bytes(t);
assert(try Parquet::new().read_bytes(b) == t);
let temps = try Parquet::new().columns(["temp"]).read_bytes(b);
assert(temps.names() == ["temp"]);
  • pub fn new() -> Parquet§

    Source

    Every column; row groups of 1048576 rows, pages of 65536 rows, Snappy, dictionaries where they pay.

  • pub fn columns(self, names: List<str>) -> Parquet§

    Source

    Read only these columns, in this order; the other column chunks are not read at all.

  • pub fn row_group_rows(self, n: usize) -> Parquet§

    Source

    Write row groups of at most n rows: smaller groups let a filtered scan skip more by their statistics.

    nabi
    let t = table::table!{ "x": [1, 2, 3, 4, 5] };
    let b = table::Parquet::new().row_group_rows(2).write_bytes(t);
    assert(try table::Parquet::new().read_bytes(b) == t);
    
  • pub fn page_rows(self, n: usize) -> Parquet§

    Source

    Write data pages of at most n rows.

  • pub fn compression(self, c: Compression) -> Parquet§

    Source

    The page compression to write (reading takes any it supports).

  • pub fn dictionary(self, yes: bool) -> Parquet§

    Source

    Whether to write dictionary pages (cat columns, and str columns with few distinct values); false writes every value PLAIN (a cat column still reads back as cat, through the Arrow schema the file carries).

  • pub fn read_bytes(self, b: List<u8>) throws (TableError) -> Table§

    Source

    The table in b.

  • pub fn read_file(self, path: str) throws (TableError) -> Table§

    Source

    The table in the file at path.

  • pub fn write_bytes(self, t: Table) -> List<u8>§

    Source

    t as Parquet bytes.

  • pub fn write_file(self, t: Table, path: str) throws (TableError)§

    Source

    Write t to path, replacing it.

Enums

CompressionSource

pub enum Compression

The page compression a written file uses.

nabi
use table::{Compression, Parquet};
let t = table::table!{ "x": [1, 2, 3] };
let b = Parquet::new().compression(Compression::None).write_bytes(t);
assert(try Parquet::new().read_bytes(b) == t);
  • Snappy§

    Source

    Snappy: fast, about 2x on typical tables; the default, as in pyarrow and Polars.

Functions

read_parquetSource

pub fn read_parquet(path: str) throws (TableError) -> Table

The Parquet file at path: Parquet::new().read_file(path).

nabi
let t = try "trips.parquet" |> table::read_parquet;

write_parquetSource

pub fn write_parquet(t: Table, path: str) throws (TableError)

Write t to path as Parquet with the defaults of Parquet::new().

nabi
try t |> table::write_parquet("trips.parquet");

parquet_schemaSource

pub fn parquet_schema(b: List<u8>) throws (TableError) -> Schema

The schema of the Parquet data in b (its readable columns), from the footer alone.

nabi
let t = table::table!{ "n": [1, 2], "s": ["a", "b"] };
let s = try table::parquet_schema(table::Parquet::new().write_bytes(t));
assert(s.dtype("s") == table::DType::Str);