compact-parquet-thrift/EXPLAINER
✳ CHAPTER 03 / PARQUET DECODE

Read the bytes.
Skip the objects.

Every Parquet file carries a compact map of its own data. We walk the Thrift metadata without building object trees, decode column pages incrementally, then reconstruct real values from dictionary IDs, float bytes and boolean bits.

READER<'a> BORROWED BYTES
input: &[u8]offset: usizeheap allocations: 0
8 BYTESlocate the footer
0 HEAP ALLOCSinside the Thrift codec
64 LEVELSdefault recursion limit
NO_STDsafe Rust, no dependencies
BEFORE THE BYTES / 01

What is Thrift?

Apache Thrift is an interface-definition language and a family of serialisation protocols. A schema gives each field a number and a type; Compact Protocol packs that information into small binary structures.

struct FileMetaData { 1: i32 version; … }
BEFORE THE BYTES / 02

Why does Parquet use it?

Parquet defines metadata in parquet.thrift and stores its Compact-encoded form in file footers and page headers. It uses Thrift as a file format encoding—not for network RPC, and not for the encoded column values.

parquet.thrift → Compact bytes → footer
01 / THE FILE

The last eight bytes tell you where to look.

Parquet stores the serialized FileMetaData near the end of the object. You can locate it with two small range reads instead of downloading the whole dataset.

01A

Dissect a Parquet object

ILLUSTRATIVE FILE · 1 MiB
BYTE 0FILE SIZE: 1,048,576 BYTESEOF
SELECTED REGION 0…3
PAR1 — opening magic

The opening four bytes identify a standard unencrypted Parquet file. The footer locator checks the final four bytes separately.

2,048 B
256 B8,192 B
R2 RANGE REQUESTS
01
Read the trailerbytes=1048568-10485754-byte little-endian footer length + PAR1
02
Fetch only the footerbytes=1046520-10485672,048 bytes, held by the transport
03
Visit fields in-placescan_footer(&bytes, visitor)Offsets, compression, row groups and statistics
THE CODEC DOES NOT OWN THE FOOTER BUFFER
02 / THE WIRE

Thrift Compact is a tiny bytecode for metadata.

Apache Thrift defines typed fields and a compact binary encoding. Parquet uses its Compact Protocol to store file metadata and page headers. Step through the actual wire rules—not a screenshot of a parser.

02B

Byte-level view

0 BYTESVALID STRUCT
FIELD HEADER LENGTH / LIST VALUE STOP
BUFFER OWNED BY CALLERREADER OFFSET 0
02C

What the cursor sees

AWAITING STEP

Select a byte or press Next.

The reader advances over a borrowed &[u8] and never constructs a complete generated Thrift object graph.

HIGH 4 BITS----field-ID delta
LOW 4 BITS----wire type
02D

Decode trace

CLICK A STEP
FIELD HEADERS

Two nibbles, one byte.

The high nibble is the delta from the previous field ID; the low nibble identifies the wire type. A delta of zero means an explicit field ID follows.

SIGNED INTEGERS

Zigzag, then varint.

Negative and positive integers become small unsigned numbers before LEB128-style variable-length encoding. −1 → 1, 1 → 2.

NESTED STRUCTS

Field IDs reset per scope.

Every nested struct has its own delta context. The reader uses a scoped cursor, not a heap-allocated object tree or a heap-allocated nesting stack.

THE INTERACTIVE DECODER IS A JAVASCRIPT TEACHING MODEL. ZERO HEAP ALLOCATIONS REFERS TO THE RUST COMPACT METADATA CODEC IN THE UPLOADED SOURCE.
03 / OWNERSHIP

No generated metadata tree. No parser heap.

The input footer already exists as bytes in the transport's buffer. WCOL holds a borrowed slice, advances an offset, and emits a temporary view of each interesting column to a callback.

03A

Two ways to inspect metadata

MODEL · NOT A BENCHMARK
8
24
POTENTIAL COLUMN CHUNKS192
METADATA GRAPH OBJECTS0

The same borrowed footer is visited column by column. The codec does not allocate metadata objects. The application can choose whether to retain each result.

MEMORY OWNERSHIPBORROWED + VISITED
FOOTER BUFFER IS REAL MEMORY, OWNED OUTSIDE THE CODEC
03B

How the Rust API does it

STACK IS NOT HEAP. For row groups up to 512 columns, scan_footer uses a fixed inline stack array of ColumnChunkInfo. Wider groups take a bounded rewind-and-visit path rather than building a heap collection. The codec still requires the footer to be available as a contiguous borrowed slice.
04 / THE BOUNDARY

Thrift describes the pages. It doesn't decode them.

The same Compact Protocol is used for Parquet page headers. The compressed page payloads use separate Parquet encodings and codecs. WCOL deliberately keeps these layers apart.

04A

Follow a column page

SELECT A STAGE
→→→
01 / I/O

Transport supplies the bytes.

An R2 or S3 range request supplies a slice of the object. The transport owns the input and the limits on how much is buffered.

01 / NOT MAGIC

Allocation-free codec ≠ no memory.

Footer bytes must be buffered contiguously for the current metadata parser. Streaming page decoders may need caller-owned scratch, presence bitmaps and decompression history.

02 / DEFENSIVE

Untrusted input needs limits.

Depth is bounded (64 by default); offsets, tags and varints are checked. Global footer-size and collection-count limits belong to the caller.

03 / FORWARD COMPATIBLE

Skip fields you don't need.

The parser can recursively skip unknown values or borrow their raw encoded bytes for rewriting. No full schema-generated object model is required.

05 / THE DECODERS

A page is a pipeline, not a blob.

The Thrift PageHeader only tells us how the next bytes are encoded. The actual values pass through a separate, incremental decoder. These are the paths implemented by this crate.

IMPLEMENTED IN THE SUPPLIED CRATEFLAT COLUMNS · V1 + V2 · BORROWED INPUT · CALLER-OWNED SCRATCH
05A

What actually sits inside a page?

SELECT A LAYOUT

In V1, an optional column's definition levels and encoded values are compressed together as one page body.

PARQUET COLUMN CHUNKBYTE ORDER →
SELECTED SEGMENT

Thrift PageHeader

The page header tells the decoder which encoding and compression path follows.

SOURCE PATHsrc/pages/frame.rsALLOCATION MODELCaller-owned header scratch
05B

Explore the physical encodings

REAL BYTES WHERE SHOWN · OTHERWISE SCHEMATIC
PHYSICAL / FLOAT · PLAIN

Four bytes become one number.

EXACT ENCODED BYTES

A FLOAT value is represented by four IEEE-754 little-endian bytes. The Rust decoder reads borrowed input and emits Value::F32.

DECODER OUTPUTValue::F32(22.0)src/values/plain.rs
MEMORY OWNERSHIP

No per-value heap allocation. A partially received fixed-width value needs at most 12 bytes of carry.

DECODER COVERAGE / exact supported encoding × physical-type combinationsEXPAND MATRIX +
ENCODINGPHYSICAL TYPES / ROLEDECODER / CONSTRAINT
PLAINBOOLEAN, INT32, INT64, INT96, FLOAT, DOUBLE, BYTE_ARRAY, FIXED_LEN_BYTE_ARRAYPlainBool / PlainValues / ByteArrays / FixedByteArrays
RLEBOOLEAN; definition levelsRleBool; Levels. Boolean RLE has a 4-byte length prefix in V1 and V2
RLE_DICTIONARY (8), PLAIN_DICTIONARY (2)Dictionary-encoded data pagesDictionaryIds emits checked IDs; caller resolves strings or other values
DELTA_BINARY_PACKED (5)INT32, INT64DeltaBinary with caller-provided mini-block width workspace
DELTA_LENGTH_BYTE_ARRAY (6)BYTE_ARRAYDeltaLengthByteArrays; caller supplies lengths array
DELTA_BYTE_ARRAY (7)BYTE_ARRAY, FIXED_LEN_BYTE_ARRAYDeltaByteArrays; caller supplies prefix/suffix and previous-value scratch
DICTIONARY_PAGEPLAIN (0), legacy PLAIN_DICTIONARY (2)Entries emitted at Location::Dictionary(index), caller retains the dictionary
PAGE COMPRESSIONUNCOMPRESSED (0), SNAPPY (1)Identity or RawSnappy; other codecs require custom Inflate
This matrix describes the compact-parquet-thrift page layer, not every Parquet feature or every decoder elsewhere in the WCOL repository. Nested/repeated data and BYTE_STREAM_SPLIT are not included here.
BUILT-IN COMPRESSIONUNCOMPRESSED · RAW SNAPPY

Identity forwards borrowed bytes; RawSnappy uses caller-provided history and output buffers. Other codecs require an external Inflate implementation.

DATA SHAPESFLAT REQUIRED / OPTIONAL

Definition levels 0 or 1, repetition level 0. One-bit-per-row presence workspace for nullable columns. Nested/repeated pages are outside this assembler.

EXPLICIT LIMITATIONSNO BYTE_STREAM_SPLIT / ALP

No built-in ZSTD, GZIP or BYTE_STREAM_SPLIT value decoder here. These are limits of this crate, not general Parquet limitations.

06 / THE RECONSTRUCTION

Three column streams. One row.

Parquet stores columns separately, not row-shaped records. Choose a row below, then advance the decoder to see one dictionary-encoded string, one FLOAT, and one BOOLEAN rejoin at their shared row position.

06A

Choose the row to reconstruct

8-ROW SYNTHETIC, BYTE-ACCURATE EXAMPLE
ROWCOUNTRY BYTE_ARRAY / DICTTEMP °C FLOAT / PLAINACTIVE BOOLEAN / PLAIN
EACH COLUMN HAS ITS OWN PARQUET PAGE(S). THE SELECTED ROW NUMBER IS A LOGICAL POSITION, NOT A CONTIGUOUS RECORD ON DISK.
06B

Step through the decode

01 / 06

Stored separately.

Each selected value lives in a separate column chunk.

ROW POSITION 4 · JOIN BY ORDINAL ↓
RECONSTRUCTED ROW / CALLER-SIDE ASSEMBLY

One logical record.


          
The Rust page decoder emits typed values and numeric dictionary IDs. The caller resolves the ID and aligns the three columns by row position.
01 / DICTIONARIESThe data page contains an ID, not a string.

The dictionary page decodes to caller-managed entries. The data page returns DictionaryId(index); the caller chooses when to resolve it.

02 / FLOATSRead four bytes, emit one f32.

PlainValues<f32> accepts fragmented input and retains at most a fixed-size partial value.

03 / BOOLEANSOne byte carries eight row values.

PlainBool reads the bits least-significant first and emits each row's boolean independently.

THE ENGINEERING TRADE-OFF

From an R2 byte range to a typed value.

Borrow the metadata. Decode page bytes incrementally. Keep scratch memory caller-owned. Reconstruct only the rows and values the query needs—that is the compact I/O foundation for WCOL.

FOLLOW THE ROW ↗CRATE SOURCE ↗MORE WCOL EXPLAINERS ↗