code wiki / (root) / nx_parquet_lib.nx

nx_parquet_lib.nx

buildroot/runtime/nx_parquet_lib.nx

55423 B1352 linesdepth 2pulls 2 transitivereach 4 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_parquet_lib.nx -- THE SOVEREIGN PARQUET READER (search R0d be_bright: the BRIGHT benchmark ships as parquet). WHY. BRIGHT (huggingface xlangai/BRIGHT, cc-by-4.0, search.refs brightds26) ships twelve documents files and twelve examples files as Apache Parquet, and on 2026-09-14 the estate held no parquet, thrift-compact or snappy reader (nx_catalog ABSENT on every name tried; a corpus-complete grep over 25,141 sources found the word only in prose). A dataset the estate cannot open is a bar the estate cannot measure, so this lib is the first byte of R0d. It reads what those files carry -- BYTE_ARRAY (string) columns, flat or nested as lists, PLAIN or dictionary encoded, uncompressed or snappy, data pages V1 or V2 -- and refuses everything else BY NAME (PQ_E_UNSUPPORTED with the offending enum value left in pq[PQ_WHAT]), never a silent zero or a quietly truncated column. THE FORMAT, from the mirrored primary sources read 2026-09-14 (search.refs pqthrift26 pqenc26 thriftcompact26 snappyfmt26): file = PAR1 .. pages .. FileMetaData (thrift compact) .. i32 LE footer length .. PAR1 thrift compact: field header byte = (id delta << 4) | type, delta 0 => a zigzag i16 follows; ints are zigzag varints; binary = varint length + bytes; list header = (size << 4) | element type, size 15 => a varint size follows; a bool list element is one byte (1 or 2); a bool struct field carries its value in the type nibble; STOP = 0. schema = depth-first list, root first. A leaf's max definition level = its non-REQUIRED ancestors plus itself, its max repetition level = its REPEATED ancestors plus itself (the Dremel shredding rules): a value is present when its definition level equals the max, and a new row starts at repetition level 0. page = PageHeader (thrift) then compressed_page_size bytes. DATA_PAGE (V1) payload = [repetition levels] [definition levels] [values], each level block an i32 LE byte length then hybrid runs; DATA_PAGE_V2 = levels first, never compressed, lengths in the header, then the values (compressed iff is_compressed); DICTIONARY_PAGE = PLAIN values. Dictionary-encoded data = one byte of bit width then hybrid runs of indices. hybrid = varint header; even => an RLE run of header >> 1 copies of one value (ceil(bw / 8) bytes LE); odd => header >> 1 groups of eight bit-packed values, LSB first. snappy = varint uncompressed length, then tagged elements: 00 literal (length in the tag up to 60, else 1..4 LE bytes follow), 01 copy with a 1-byte offset (length 4..11, 11-bit offset), 10 copy with a 2-byte offset, 11 copy with a 4-byte offset (both length 1..64). EVERY READ IS BOUNDED by the buffer it reads and every write by an arena sized from the column chunk's own total_uncompressed_size (the format's bound on decoded page bytes): a decompressor is a parser pointed at foreign bytes (nx_inflate's law), so a truncated stream, a back-reference before the buffer, a level count that disagrees with the page header and a footer longer than the file each REFUSE with a distinct negative code. COMPOSES sys_read_file (buffer sized from the file, no cap), sys_mmap, sys_munmap, sys_write. Allocation happens once per open and once per column chunk read, never per page or per value. No hw writes (Rule 26). license_tier: ORIGINAL

dependencies 1 imports · 3 importers

nx_syscalls.nx nx_parquet_lib.nx nx_bright_prep.nx nx_parquet.nx nx_parquet_gate.nx

imports: nx_syscalls.nx

imported by: nx_bright_prep.nxnx_parquet.nxnx_parquet_gate.nx

structs

none

consts

39const PQ_I64: i64 = 8
40const PQ_BYTE: i64 = 255
41const PQ_BITS: i64 = 8
42const PQ_I32_LEN: i64 = 4
43const PQ_MAGIC_LEN: i64 = 4
44const PQ_TAIL_LEN: i64 = 8 // i32 footer length + PAR1
45const PQ_MAGIC_P: i64 = 80
46const PQ_MAGIC_A: i64 = 65
47const PQ_MAGIC_R: i64 = 82
48const PQ_MAGIC_1: i64 = 49
49const PQ_NONE: i64 = 0 - 1
50const PQ_NL: i64 = 10
51const PQ_CR: i64 = 13
52const PQ_TAB: i64 = 9
53const PQ_SPACE: i64 = 32
54const PQ_PIPE: i64 = 124
55const PQ_MINUS: i64 = 45
56const PQ_EQ: i64 = 61
57const PQ_DIGIT0: i64 = 48
58const PQ_DECIMAL: i64 = 10
59const PQ_ARENA_SLACK: i64 = 64 // headroom past the format's own bound, never a size to tune
60const PQ_MAX_BITWIDTH: i64 = 32 // a parquet level or dictionary index never exceeds 32 bits
61const PQ_HYBRID_GROUP: i64 = 8 // bit-packed values come in groups of eight
62const PQ_I64_MAX: i64 = 9223372036854775807
65const PQ_E_MAGIC: i64 = 0 - 1 // not a parquet file
66const PQ_E_TRUNC: i64 = 0 - 2 // a length points past the bytes
67const PQ_E_THRIFT: i64 = 0 - 3 // the footer or a page header does not decode
68const PQ_E_UNSUPPORTED: i64 = 0 - 4 // a type, encoding, codec or page kind not yet measured (pq[PQ_WHAT])
69const PQ_E_SNAPPY: i64 = 0 - 5 // the snappy stream is corrupt or disagrees with the header
70const PQ_E_CAPACITY: i64 = 0 - 6 // output would exceed the arena or the entry table
71const PQ_E_ORDER: i64 = 0 - 7 // row groups met before the schema in the footer
72const PQ_E_LEVELS: i64 = 0 - 8 // level, value or dictionary counts disagree with the page header
73const PQ_E_COLUMNS: i64 = 0 - 9 // a row group's column count differs from the schema's leaf count
74const PQ_E_ARG: i64 = 0 - 10 // a row group or leaf index out of range
75const PQ_E_OPEN: i64 = 0 - 11 // the file cannot be read
78const TC_STOP: i64 = 0
79const TC_BTRUE: i64 = 1
80const TC_BFALSE: i64 = 2
81const TC_I8: i64 = 3
82const TC_I16: i64 = 4
83const TC_I32: i64 = 5
84const TC_I64: i64 = 6
85const TC_DOUBLE: i64 = 7
86const TC_BINARY: i64 = 8
87const TC_LIST: i64 = 9
88const TC_SET: i64 = 10
89const TC_MAP: i64 = 11
90const TC_STRUCT: i64 = 12
91const TC_UUID: i64 = 13
92const TC_DOUBLE_BYTES: i64 = 8
93const TC_UUID_BYTES: i64 = 16
94const TC_NIBBLE: i64 = 15
95const TC_LONG_FORM: i64 = 15
96const TC_TYPE_SHIFT: i64 = 4
97const TC_VARINT_MAX: i64 = 10
98const TC_VARINT_DATA: i64 = 127
99const TC_VARINT_MORE: i64 = 128
100const TC_VARINT_SHIFT: i64 = 7
102const TC_BUF: i64 = 0
103const TC_POS: i64 = 1
104const TC_END: i64 = 2
105const TC_ERR: i64 = 3
106const TC_FID: i64 = 4
107const TC_LAST: i64 = 5
108const TC_ET: i64 = 6
109const TC_SLOTS: i64 = 7
111const TS_KIND: i64 = 0
112const TS_REM: i64 = 1
113const TS_ET: i64 = 2
114const TS_VT: i64 = 3
115const TS_LAST: i64 = 4
116const TS_SLOTS: i64 = 5
117const TS_DEPTH: i64 = 64 // parquet metadata nests under ten deep; beyond this is a refusal, not a guess
118const TK_STRUCT: i64 = 0
119const TK_LIST: i64 = 1
120const TK_MAP: i64 = 2
123const PQ_T_BOOLEAN: i64 = 0
124const PQ_T_INT32: i64 = 1
125const PQ_T_INT64: i64 = 2
126const PQ_T_INT96: i64 = 3
127const PQ_T_FLOAT: i64 = 4
128const PQ_T_DOUBLE: i64 = 5
129const PQ_T_BYTE_ARRAY: i64 = 6
130const PQ_T_FIXED: i64 = 7
131const PQ_ENC_PLAIN: i64 = 0
132const PQ_ENC_PLAIN_DICT: i64 = 2
133const PQ_ENC_RLE: i64 = 3
134const PQ_ENC_BITPACKED: i64 = 4
135const PQ_ENC_RLE_DICT: i64 = 8
136const PQ_CODEC_NONE: i64 = 0
137const PQ_CODEC_SNAPPY: i64 = 1
138const PQ_PAGE_DATA: i64 = 0
139const PQ_PAGE_INDEX: i64 = 1
140const PQ_PAGE_DICT: i64 = 2
141const PQ_PAGE_DATA2: i64 = 3
142const PQ_REP_REQUIRED: i64 = 0
143const PQ_REP_OPTIONAL: i64 = 1
144const PQ_REP_REPEATED: i64 = 2
146const FMD_F_VERSION: i64 = 1
147const FMD_F_SCHEMA: i64 = 2
148const FMD_F_NROWS: i64 = 3
149const FMD_F_RGS: i64 = 4
150const FMD_F_CREATED: i64 = 6
151const SE_F_TYPE: i64 = 1
152const SE_F_REP: i64 = 3
153const SE_F_NAME: i64 = 4
154const SE_F_NCHILD: i64 = 5
155const SE_F_CONV: i64 = 6
156const RG_F_COLS: i64 = 1
157const RG_F_TOTAL: i64 = 2
158const RG_F_NROWS: i64 = 3
159const CC_F_META: i64 = 3
160const CM_F_TYPE: i64 = 1
161const CM_F_ENCS: i64 = 2
162const CM_F_PATH: i64 = 3
163const CM_F_CODEC: i64 = 4
164const CM_F_NVALS: i64 = 5
165const CM_F_UNCOMP: i64 = 6
166const CM_F_COMP: i64 = 7
167const CM_F_DATAOFF: i64 = 9
168const CM_F_DICTOFF: i64 = 11
169const PH_F_TYPE: i64 = 1
170const PH_F_UNCOMP: i64 = 2
171const PH_F_COMP: i64 = 3
172const PH_F_DPH: i64 = 5
173const PH_F_DICTH: i64 = 7
174const PH_F_DPH2: i64 = 8
175const DP_F_NVALS: i64 = 1
176const DP_F_ENC: i64 = 2
177const DP_F_DEFENC: i64 = 3
178const DP_F_REPENC: i64 = 4
179const DI_F_NVALS: i64 = 1
180const DI_F_ENC: i64 = 2
181const D2_F_NVALS: i64 = 1
182const D2_F_NNULLS: i64 = 2
183const D2_F_NROWS: i64 = 3
184const D2_F_ENC: i64 = 4
185const D2_F_DEFLEN: i64 = 5
186const D2_F_REPLEN: i64 = 6
187const D2_F_ISCOMP: i64 = 7
190const PQ_BUF: i64 = 0
191const PQ_LEN: i64 = 1
192const PQ_META_OFF: i64 = 2
193const PQ_META_LEN: i64 = 3
194const PQ_NSE: i64 = 4
195const PQ_SE: i64 = 5
196const PQ_NLEAF: i64 = 6
197const PQ_NRG: i64 = 7
198const PQ_RG: i64 = 8
199const PQ_CC: i64 = 9
200const PQ_NROWS: i64 = 10
201const PQ_ERR: i64 = 11
202const PQ_CREATED_OFF: i64 = 12
203const PQ_CREATED_LEN: i64 = 13
204const PQ_VERSION: i64 = 14
205const PQ_WHAT: i64 = 15
206const PQ_CUR: i64 = 16
207const PQ_STK: i64 = 17
208const PQ_SLOTS: i64 = 18
210const SE_TYPE: i64 = 0
211const SE_REP: i64 = 1
212const SE_NAMEOFF: i64 = 2
213const SE_NAMELEN: i64 = 3
214const SE_NCHILD: i64 = 4
215const SE_CONV: i64 = 5
216const SE_MAXDEF: i64 = 6
217const SE_MAXREP: i64 = 7
218const SE_LEAF: i64 = 8
219const SE_PARENT: i64 = 9
220const SE_SLOTS: i64 = 10
222const RG_NROWS: i64 = 0
223const RG_TOTAL: i64 = 1
224const RG_SLOTS: i64 = 2
226const CC_TYPE: i64 = 0
227const CC_CODEC: i64 = 1
228const CC_NVALS: i64 = 2
229const CC_UNCOMP: i64 = 3
230const CC_COMP: i64 = 4
231const CC_DATAOFF: i64 = 5
232const CC_DICTOFF: i64 = 6
233const CC_ENCMASK: i64 = 7
234const CC_PATHOFF: i64 = 8
235const CC_PATHLEN: i64 = 9
236const CC_SLOTS: i64 = 10
238const PH_TYPE: i64 = 0
239const PH_USZ: i64 = 1
240const PH_CSZ: i64 = 2
241const PH_NV: i64 = 3
242const PH_ENC: i64 = 4
243const PH_DEFENC: i64 = 5
244const PH_REPENC: i64 = 6
245const PH_NNULLS: i64 = 7
246const PH_NROWS: i64 = 8
247const PH_DEFLEN: i64 = 9
248const PH_REPLEN: i64 = 10
249const PH_ISCOMP: i64 = 11
250const PH_DICTN: i64 = 12
251const PH_DICTENC: i64 = 13
252const PH_SLOTS: i64 = 14
254const PR_ARENA: i64 = 0
255const PR_ACAP: i64 = 1
256const PR_AUSED: i64 = 2
257const PR_OFF: i64 = 3
258const PR_LEN: i64 = 4
259const PR_DEF: i64 = 5
260const PR_REP: i64 = 6
261const PR_ROW: i64 = 7
262const PR_CAP: i64 = 8
263const PR_N: i64 = 9
264const PR_NONNULL: i64 = 10
265const PR_PAGES: i64 = 11
266const PR_DICTN: i64 = 12
267const PR_DOFF: i64 = 13
268const PR_DLEN: i64 = 14
269const PR_ROWS: i64 = 15
270const PR_ENCMASK: i64 = 16
271const PR_PTYPES: i64 = 17
272const PR_PH: i64 = 18
273const PR_SLOTS: i64 = 19
275const WB_BUF: i64 = 0
276const WB_CAP: i64 = 1
277const WB_USED: i64 = 2
278const WB_FD: i64 = 3
279const WB_ERR: i64 = 4
280const WB_TOTAL: i64 = 5
281const WB_NUM: i64 = 6
282const WB_SLOTS: i64 = 7
283const WB_DEFAULT_CAP: i64 = 1048576 // one MiB batched per write: syscalls per megabyte, never per row
284const WB_NUM_CAP: i64 = 24
1279const PT_ROWS: i64 = 0
1280const PT_WRITTEN: i64 = 1
1281const PT_NULLROWS: i64 = 2
1282const PT_BYTES: i64 = 3
1283const PT_SLOTS: i64 = 4
1284const PQ_TMP_SUFFIX: *u8 = ".tmp"
1285const PQ_PATH_CAP: i64 = 1024

functions

289func wb_new(fd: i64) -> *i64
called by 4: bp_runmainmainpq_tsv calls 1: sys_mmap
300func wb_flush(w: *i64) -> i64
313func wb_byte(w: *i64, ch: i64) -> i64
320func wb_bytes(w: *i64, src: *u8, off: i64, n: i64) -> i64
called by 2: np_namenp_meta calls 1: wb_byte
326func wb_cell(w: *i64, src: *u8, off: i64, n: i64) -> i64
called by 4: bp_runnp_metanp_showpq_tsv calls 1: wb_byte
336func wb_puts(w: *i64, s: *u8) -> i64
341func wb_putn(w: *i64, v0: i64) -> i64
called by 4: np_metanp_countnp_showwb_kv calls 1: wb_byte
351func wb_kv(w: *i64, key: *u8, v: i64) -> i64
362func tc_init(c: *i64, buf: *u8, pos: i64, end: i64) -> i64
372func tc_byte(c: *i64) -> i64
380func tc_varint(c: *i64) -> i64
396func tc_zz(c: *i64) -> i64
402func tc_field(c: *i64) -> i64
413func tc_list_head(c: *i64) -> i64
421func tc_skip_n(c: *i64, n: i64) -> i64
428func tc_binary(c: *i64) -> i64
436func tc_skip_scalar(c: *i64, t: i64, elem: i64) -> i64
called by 1: tc_skip calls 2: tc_skip_ntc_varint
448func tc_open(c: *i64, st: *i64, d: i64, t: i64) -> i64
471func tc_skip(c: *i64, t: i64, st: *i64) -> i64
512func pq_le32(b: *u8, p: i64) -> i64
516func pq_bitwidth(maxv: i64) -> i64
called by 1: pq_read_column
522func pq_fill(a: *i64, base: i64, n: i64, v: i64) -> i64
called by 1: pq_read_column
527func pq_se(pq: *i64, i: i64) -> *i64
530func pq_rg(pq: *i64, r: i64) -> *i64
533func pq_cc(pq: *i64, r: i64, leaf: i64) -> *i64
537func pq_leaf_index(pq: *i64, leaf: i64) -> i64
called by 3: np_countpq_read_columnpq_tsv calls 1: pq_se
549func pq_leaf_named(pq: *i64, s: *u8) -> i64
called by 3: bp_runnp_leaf_argmain calls 1: pq_se
579func pq_parse_columnmeta(pq: *i64, c: *i64, st: *i64, cc: *i64) -> i64
614func pq_parse_columnchunk(pq: *i64, c: *i64, st: *i64, cc: *i64) -> i64
628func pq_parse_rowgroups(pq: *i64, c: *i64, st: *i64) -> i64
676func pq_schema_levels(pq: *i64) -> i64
called by 1: pq_parse_schema calls 2: sys_mmappq_se
718func pq_parse_schema(pq: *i64, c: *i64, st: *i64) -> i64
780func pq_open(pq: *i64, path: *u8) -> i64
818func pq_parse_sub(c: *i64, st: *i64, ph: *i64, which: i64) -> i64
854func pq_parse_pageheader(pq: *i64, pos: i64, ph: *i64) -> i64
882func pq_snappy(src: *u8, s: i64, e: i64, out: *u8, o: i64, ocap: i64) -> i64
called by 2: mainpq_inflate_page calls 1: pq_le32
952func pq_inflate_page(pq: *i64, codec: i64, src: *u8, s: i64, e: i64, arena: *u8, a0: i64, acap: i64, usz: i64) -> i64
called by 1: pq_read_column calls 1: pq_snappy
969func pq_hybrid(src: *u8, s: i64, e: i64, bw: i64, n: i64, out: *i64, cap: i64) -> i64
called by 2: mainpq_read_column
1028func pq_plain_bytes(arena: *u8, s: i64, e: i64, n: i64, off: *i64, len: *i64) -> i64
called by 1: pq_read_column calls 1: pq_le32
1045func pr_alloc(pq: *i64, r: i64, leaf: i64) -> *i64
1066func pr_free(pr: *i64) -> i64
1082func pq_read_column(pq: *i64, r: i64, leaf: i64, pr: *i64) -> i64
1261func pq_errname(rc: i64) -> *u8
called by 2: mainnp_refusal
1290func pq_tsv(pq: *i64, la: i64, lb: i64, out: *u8, stats: *i64) -> i64