The writer takes exactly what the reader produces: an ArrayArena and the
indices of the top-level arrays in it. That makes a round trip one line, and it
means anything the reader can decode, the writer can write back.
from parquet import ParquetReader, ParquetWriter, WriterOptions
var r = ParquetReader.open("in.parquet")
var t = r.read_table()
var opts = WriterOptions()
opts.codec = CompressionCodec.SNAPPY.value
var w = ParquetWriter(opts^)
for b in t.batches:
w.write_batch(b.arena, b.roots)
var bytes = w^.finish()
What it writes: Parquet 2.6 metadata with v1 data pages, PLAIN and
RLE_DICTIONARY values, RLE levels, three-level lists, key_value maps,
structs, field ids, per-chunk statistics with the sort order each logical type
requires, an OffsetIndex and a ColumnIndex per chunk, and key/value
metadata. Decimals go out as FIXED_LEN_BYTE_ARRAY(16), which is legal for
every precision Arrow can hold.
Structs
WriterOptions
struct WriterOptions
How to write. Every field has a sensible default.
Implements Copyable, Defaultable, Movable
- Fields
codec: Int32row_group_size: Intdata_page_size: Int: Target uncompressed bytes of values per data page.use_dictionary: Boolwrite_statistics: Boolwrite_page_index: Boolcreated_by: String
WNode
struct WNode
One node of the tree the writer walks, mirroring the Arrow field tree.
Implements Copyable, Defaultable, Movable
- Fields
name: Stringkind: Intarrow: ArrowTypenullable: Boolfield_id: Int32children: List[Int]def_level: Intrep_level: Intelem_def_level: Intelem_rep_level: Intleaf: Int
WLeaf
struct WLeaf
A column the writer will produce chunks for.
Implements Copyable, Defaultable, Movable
- Fields
path: List[String]arrow: ArrowTypephysical: Int32type_length: Intmax_def: Intmax_rep: Intfield_id: Int32
WriteSchema
struct WriteSchema
The writer's mirror of the Arrow field tree, plus the Parquet schema.
Implements Copyable, Defaultable, Movable
- Fields
nodes: List[WNode]roots: List[Int]leaves: List[WLeaf]elements: List[SchemaElement]
LeafBuffer
struct LeafBuffer
Implements Copyable, Defaultable, Movable
- Fields
defs: List[UInt16]reps: List[UInt16]values: PhysBuffer
DictBuilder
struct DictBuilder
Distinct values in first-seen order, with an open-addressed index.
The index is a flat power-of-two table of Int32 dictionary indices with
linear probing — one array, no per-bucket allocation, no Dict and no
List of collisions.
A 4- or 8-byte fixed-width column sets key_width and is indexed by the
integer value itself: the hash is a multiply-shift of the key and the
comparison is an integer compare, so a value costs no span construction
and no byte loop at all. Everything else hashes and compares bytes.
Implements Defaultable, Movable
- Fields
values: PhysBufferslots: List[Int32]mask: UInt64used: Intkey_width: Int: 4 or 8 for the integer-keyed mode, 0 for the byte-keyed one.
__init__
def __init__(out self, kind: Int, width: Int, expect: Int = Int(0))
index_of_key
def index_of_key(mut self, key: UInt64) -> Int
The dictionary index of an integer-keyed value, adding it if new.
index_of
def index_of(mut self, v: Span[UInt8]) -> Int
ParquetWriter
struct ParquetWriter[Codecs: CodecSet = DefaultCodecs]
Writes Arrow arrays out as Parquet. One write_batch per record batch.
Implements Movable
- Fields
options: WriterOptionsschema: WriteSchemaout: List[UInt8]row_groups: List[RowGroup]offset_indexes: List[List[OffsetIndex]]column_indexes: List[List[ColumnIndex]]num_rows: Int64kv: List[KeyValue]
__init__
def __init__(out self, var options: WriterOptions)
write_batch
def write_batch(mut self, arena: ArrayArena, roots: List[Int])
Write one record batch, split into row groups of row_group_size.
finish
def finish(deinit self) -> List[UInt8]
Close the file and return its bytes.