nx_parquet_lib.nx
buildroot/runtime/nx_parquet_lib.nx
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
imports: nx_syscalls.nx
imported by: nx_bright_prep.nxnx_parquet.nxnx_parquet_gate.nx
structs
| none |
consts
| 39 | const PQ_I64: i64 = 8 |
| 40 | const PQ_BYTE: i64 = 255 |
| 41 | const PQ_BITS: i64 = 8 |
| 42 | const PQ_I32_LEN: i64 = 4 |
| 43 | const PQ_MAGIC_LEN: i64 = 4 |
| 44 | const PQ_TAIL_LEN: i64 = 8 // i32 footer length + PAR1 |
| 45 | const PQ_MAGIC_P: i64 = 80 |
| 46 | const PQ_MAGIC_A: i64 = 65 |
| 47 | const PQ_MAGIC_R: i64 = 82 |
| 48 | const PQ_MAGIC_1: i64 = 49 |
| 49 | const PQ_NONE: i64 = 0 - 1 |
| 50 | const PQ_NL: i64 = 10 |
| 51 | const PQ_CR: i64 = 13 |
| 52 | const PQ_TAB: i64 = 9 |
| 53 | const PQ_SPACE: i64 = 32 |
| 54 | const PQ_PIPE: i64 = 124 |
| 55 | const PQ_MINUS: i64 = 45 |
| 56 | const PQ_EQ: i64 = 61 |
| 57 | const PQ_DIGIT0: i64 = 48 |
| 58 | const PQ_DECIMAL: i64 = 10 |
| 59 | const PQ_ARENA_SLACK: i64 = 64 // headroom past the format's own bound, never a size to tune |
| 60 | const PQ_MAX_BITWIDTH: i64 = 32 // a parquet level or dictionary index never exceeds 32 bits |
| 61 | const PQ_HYBRID_GROUP: i64 = 8 // bit-packed values come in groups of eight |
| 62 | const PQ_I64_MAX: i64 = 9223372036854775807 |
| 65 | const PQ_E_MAGIC: i64 = 0 - 1 // not a parquet file |
| 66 | const PQ_E_TRUNC: i64 = 0 - 2 // a length points past the bytes |
| 67 | const PQ_E_THRIFT: i64 = 0 - 3 // the footer or a page header does not decode |
| 68 | const PQ_E_UNSUPPORTED: i64 = 0 - 4 // a type, encoding, codec or page kind not yet measured (pq[PQ_WHAT]) |
| 69 | const PQ_E_SNAPPY: i64 = 0 - 5 // the snappy stream is corrupt or disagrees with the header |
| 70 | const PQ_E_CAPACITY: i64 = 0 - 6 // output would exceed the arena or the entry table |
| 71 | const PQ_E_ORDER: i64 = 0 - 7 // row groups met before the schema in the footer |
| 72 | const PQ_E_LEVELS: i64 = 0 - 8 // level, value or dictionary counts disagree with the page header |
| 73 | const PQ_E_COLUMNS: i64 = 0 - 9 // a row group's column count differs from the schema's leaf count |
| 74 | const PQ_E_ARG: i64 = 0 - 10 // a row group or leaf index out of range |
| 75 | const PQ_E_OPEN: i64 = 0 - 11 // the file cannot be read |
| 78 | const TC_STOP: i64 = 0 |
| 79 | const TC_BTRUE: i64 = 1 |
| 80 | const TC_BFALSE: i64 = 2 |
| 81 | const TC_I8: i64 = 3 |
| 82 | const TC_I16: i64 = 4 |
| 83 | const TC_I32: i64 = 5 |
| 84 | const TC_I64: i64 = 6 |
| 85 | const TC_DOUBLE: i64 = 7 |
| 86 | const TC_BINARY: i64 = 8 |
| 87 | const TC_LIST: i64 = 9 |
| 88 | const TC_SET: i64 = 10 |
| 89 | const TC_MAP: i64 = 11 |
| 90 | const TC_STRUCT: i64 = 12 |
| 91 | const TC_UUID: i64 = 13 |
| 92 | const TC_DOUBLE_BYTES: i64 = 8 |
| 93 | const TC_UUID_BYTES: i64 = 16 |
| 94 | const TC_NIBBLE: i64 = 15 |
| 95 | const TC_LONG_FORM: i64 = 15 |
| 96 | const TC_TYPE_SHIFT: i64 = 4 |
| 97 | const TC_VARINT_MAX: i64 = 10 |
| 98 | const TC_VARINT_DATA: i64 = 127 |
| 99 | const TC_VARINT_MORE: i64 = 128 |
| 100 | const TC_VARINT_SHIFT: i64 = 7 |
| 102 | const TC_BUF: i64 = 0 |
| 103 | const TC_POS: i64 = 1 |
| 104 | const TC_END: i64 = 2 |
| 105 | const TC_ERR: i64 = 3 |
| 106 | const TC_FID: i64 = 4 |
| 107 | const TC_LAST: i64 = 5 |
| 108 | const TC_ET: i64 = 6 |
| 109 | const TC_SLOTS: i64 = 7 |
| 111 | const TS_KIND: i64 = 0 |
| 112 | const TS_REM: i64 = 1 |
| 113 | const TS_ET: i64 = 2 |
| 114 | const TS_VT: i64 = 3 |
| 115 | const TS_LAST: i64 = 4 |
| 116 | const TS_SLOTS: i64 = 5 |
| 117 | const TS_DEPTH: i64 = 64 // parquet metadata nests under ten deep; beyond this is a refusal, not a guess |
| 118 | const TK_STRUCT: i64 = 0 |
| 119 | const TK_LIST: i64 = 1 |
| 120 | const TK_MAP: i64 = 2 |
| 123 | const PQ_T_BOOLEAN: i64 = 0 |
| 124 | const PQ_T_INT32: i64 = 1 |
| 125 | const PQ_T_INT64: i64 = 2 |
| 126 | const PQ_T_INT96: i64 = 3 |
| 127 | const PQ_T_FLOAT: i64 = 4 |
| 128 | const PQ_T_DOUBLE: i64 = 5 |
| 129 | const PQ_T_BYTE_ARRAY: i64 = 6 |
| 130 | const PQ_T_FIXED: i64 = 7 |
| 131 | const PQ_ENC_PLAIN: i64 = 0 |
| 132 | const PQ_ENC_PLAIN_DICT: i64 = 2 |
| 133 | const PQ_ENC_RLE: i64 = 3 |
| 134 | const PQ_ENC_BITPACKED: i64 = 4 |
| 135 | const PQ_ENC_RLE_DICT: i64 = 8 |
| 136 | const PQ_CODEC_NONE: i64 = 0 |
| 137 | const PQ_CODEC_SNAPPY: i64 = 1 |
| 138 | const PQ_PAGE_DATA: i64 = 0 |
| 139 | const PQ_PAGE_INDEX: i64 = 1 |
| 140 | const PQ_PAGE_DICT: i64 = 2 |
| 141 | const PQ_PAGE_DATA2: i64 = 3 |
| 142 | const PQ_REP_REQUIRED: i64 = 0 |
| 143 | const PQ_REP_OPTIONAL: i64 = 1 |
| 144 | const PQ_REP_REPEATED: i64 = 2 |
| 146 | const FMD_F_VERSION: i64 = 1 |
| 147 | const FMD_F_SCHEMA: i64 = 2 |
| 148 | const FMD_F_NROWS: i64 = 3 |
| 149 | const FMD_F_RGS: i64 = 4 |
| 150 | const FMD_F_CREATED: i64 = 6 |
| 151 | const SE_F_TYPE: i64 = 1 |
| 152 | const SE_F_REP: i64 = 3 |
| 153 | const SE_F_NAME: i64 = 4 |
| 154 | const SE_F_NCHILD: i64 = 5 |
| 155 | const SE_F_CONV: i64 = 6 |
| 156 | const RG_F_COLS: i64 = 1 |
| 157 | const RG_F_TOTAL: i64 = 2 |
| 158 | const RG_F_NROWS: i64 = 3 |
| 159 | const CC_F_META: i64 = 3 |
| 160 | const CM_F_TYPE: i64 = 1 |
| 161 | const CM_F_ENCS: i64 = 2 |
| 162 | const CM_F_PATH: i64 = 3 |
| 163 | const CM_F_CODEC: i64 = 4 |
| 164 | const CM_F_NVALS: i64 = 5 |
| 165 | const CM_F_UNCOMP: i64 = 6 |
| 166 | const CM_F_COMP: i64 = 7 |
| 167 | const CM_F_DATAOFF: i64 = 9 |
| 168 | const CM_F_DICTOFF: i64 = 11 |
| 169 | const PH_F_TYPE: i64 = 1 |
| 170 | const PH_F_UNCOMP: i64 = 2 |
| 171 | const PH_F_COMP: i64 = 3 |
| 172 | const PH_F_DPH: i64 = 5 |
| 173 | const PH_F_DICTH: i64 = 7 |
| 174 | const PH_F_DPH2: i64 = 8 |
| 175 | const DP_F_NVALS: i64 = 1 |
| 176 | const DP_F_ENC: i64 = 2 |
| 177 | const DP_F_DEFENC: i64 = 3 |
| 178 | const DP_F_REPENC: i64 = 4 |
| 179 | const DI_F_NVALS: i64 = 1 |
| 180 | const DI_F_ENC: i64 = 2 |
| 181 | const D2_F_NVALS: i64 = 1 |
| 182 | const D2_F_NNULLS: i64 = 2 |
| 183 | const D2_F_NROWS: i64 = 3 |
| 184 | const D2_F_ENC: i64 = 4 |
| 185 | const D2_F_DEFLEN: i64 = 5 |
| 186 | const D2_F_REPLEN: i64 = 6 |
| 187 | const D2_F_ISCOMP: i64 = 7 |
| 190 | const PQ_BUF: i64 = 0 |
| 191 | const PQ_LEN: i64 = 1 |
| 192 | const PQ_META_OFF: i64 = 2 |
| 193 | const PQ_META_LEN: i64 = 3 |
| 194 | const PQ_NSE: i64 = 4 |
| 195 | const PQ_SE: i64 = 5 |
| 196 | const PQ_NLEAF: i64 = 6 |
| 197 | const PQ_NRG: i64 = 7 |
| 198 | const PQ_RG: i64 = 8 |
| 199 | const PQ_CC: i64 = 9 |
| 200 | const PQ_NROWS: i64 = 10 |
| 201 | const PQ_ERR: i64 = 11 |
| 202 | const PQ_CREATED_OFF: i64 = 12 |
| 203 | const PQ_CREATED_LEN: i64 = 13 |
| 204 | const PQ_VERSION: i64 = 14 |
| 205 | const PQ_WHAT: i64 = 15 |
| 206 | const PQ_CUR: i64 = 16 |
| 207 | const PQ_STK: i64 = 17 |
| 208 | const PQ_SLOTS: i64 = 18 |
| 210 | const SE_TYPE: i64 = 0 |
| 211 | const SE_REP: i64 = 1 |
| 212 | const SE_NAMEOFF: i64 = 2 |
| 213 | const SE_NAMELEN: i64 = 3 |
| 214 | const SE_NCHILD: i64 = 4 |
| 215 | const SE_CONV: i64 = 5 |
| 216 | const SE_MAXDEF: i64 = 6 |
| 217 | const SE_MAXREP: i64 = 7 |
| 218 | const SE_LEAF: i64 = 8 |
| 219 | const SE_PARENT: i64 = 9 |
| 220 | const SE_SLOTS: i64 = 10 |
| 222 | const RG_NROWS: i64 = 0 |
| 223 | const RG_TOTAL: i64 = 1 |
| 224 | const RG_SLOTS: i64 = 2 |
| 226 | const CC_TYPE: i64 = 0 |
| 227 | const CC_CODEC: i64 = 1 |
| 228 | const CC_NVALS: i64 = 2 |
| 229 | const CC_UNCOMP: i64 = 3 |
| 230 | const CC_COMP: i64 = 4 |
| 231 | const CC_DATAOFF: i64 = 5 |
| 232 | const CC_DICTOFF: i64 = 6 |
| 233 | const CC_ENCMASK: i64 = 7 |
| 234 | const CC_PATHOFF: i64 = 8 |
| 235 | const CC_PATHLEN: i64 = 9 |
| 236 | const CC_SLOTS: i64 = 10 |
| 238 | const PH_TYPE: i64 = 0 |
| 239 | const PH_USZ: i64 = 1 |
| 240 | const PH_CSZ: i64 = 2 |
| 241 | const PH_NV: i64 = 3 |
| 242 | const PH_ENC: i64 = 4 |
| 243 | const PH_DEFENC: i64 = 5 |
| 244 | const PH_REPENC: i64 = 6 |
| 245 | const PH_NNULLS: i64 = 7 |
| 246 | const PH_NROWS: i64 = 8 |
| 247 | const PH_DEFLEN: i64 = 9 |
| 248 | const PH_REPLEN: i64 = 10 |
| 249 | const PH_ISCOMP: i64 = 11 |
| 250 | const PH_DICTN: i64 = 12 |
| 251 | const PH_DICTENC: i64 = 13 |
| 252 | const PH_SLOTS: i64 = 14 |
| 254 | const PR_ARENA: i64 = 0 |
| 255 | const PR_ACAP: i64 = 1 |
| 256 | const PR_AUSED: i64 = 2 |
| 257 | const PR_OFF: i64 = 3 |
| 258 | const PR_LEN: i64 = 4 |
| 259 | const PR_DEF: i64 = 5 |
| 260 | const PR_REP: i64 = 6 |
| 261 | const PR_ROW: i64 = 7 |
| 262 | const PR_CAP: i64 = 8 |
| 263 | const PR_N: i64 = 9 |
| 264 | const PR_NONNULL: i64 = 10 |
| 265 | const PR_PAGES: i64 = 11 |
| 266 | const PR_DICTN: i64 = 12 |
| 267 | const PR_DOFF: i64 = 13 |
| 268 | const PR_DLEN: i64 = 14 |
| 269 | const PR_ROWS: i64 = 15 |
| 270 | const PR_ENCMASK: i64 = 16 |
| 271 | const PR_PTYPES: i64 = 17 |
| 272 | const PR_PH: i64 = 18 |
| 273 | const PR_SLOTS: i64 = 19 |
| 275 | const WB_BUF: i64 = 0 |
| 276 | const WB_CAP: i64 = 1 |
| 277 | const WB_USED: i64 = 2 |
| 278 | const WB_FD: i64 = 3 |
| 279 | const WB_ERR: i64 = 4 |
| 280 | const WB_TOTAL: i64 = 5 |
| 281 | const WB_NUM: i64 = 6 |
| 282 | const WB_SLOTS: i64 = 7 |
| 283 | const WB_DEFAULT_CAP: i64 = 1048576 // one MiB batched per write: syscalls per megabyte, never per row |
| 284 | const WB_NUM_CAP: i64 = 24 |
| 1279 | const PT_ROWS: i64 = 0 |
| 1280 | const PT_WRITTEN: i64 = 1 |
| 1281 | const PT_NULLROWS: i64 = 2 |
| 1282 | const PT_BYTES: i64 = 3 |
| 1283 | const PT_SLOTS: i64 = 4 |
| 1284 | const PQ_TMP_SUFFIX: *u8 = ".tmp" |
| 1285 | const PQ_PATH_CAP: i64 = 1024 |
functions
| 289 | func wb_new(fd: i64) -> *i64 |
| 300 | func wb_flush(w: *i64) -> i64 |
| 313 | func wb_byte(w: *i64, ch: i64) -> i64 |
| 320 | func wb_bytes(w: *i64, src: *u8, off: i64, n: i64) -> i64 |
| 326 | func wb_cell(w: *i64, src: *u8, off: i64, n: i64) -> i64 |
| 336 | func wb_puts(w: *i64, s: *u8) -> i64 |
| 341 | func wb_putn(w: *i64, v0: i64) -> i64 |
| 351 | func wb_kv(w: *i64, key: *u8, v: i64) -> i64 |
| 362 | func tc_init(c: *i64, buf: *u8, pos: i64, end: i64) -> i64 |
| 372 | func tc_byte(c: *i64) -> i64 |
| 380 | func tc_varint(c: *i64) -> i64 |
| 396 | func tc_zz(c: *i64) -> i64 called by 8: maintc_fieldpq_parse_columnmetapq_parse_rowgroupspq_parse_schemapq_parse_footer+2 calls 1: tc_varint |
| 402 | func tc_field(c: *i64) -> i64 called by 9: maintc_skippq_parse_columnmetapq_parse_columnchunkpq_parse_rowgroupspq_parse_schema+3 calls 2: tc_bytetc_zz |
| 413 | func tc_list_head(c: *i64) -> i64 called by 5: maintc_openpq_parse_columnmetapq_parse_rowgroupspq_parse_schema calls 2: tc_bytetc_varint |
| 421 | func tc_skip_n(c: *i64, n: i64) -> i64 |
| 428 | func tc_binary(c: *i64) -> i64 |
| 436 | func tc_skip_scalar(c: *i64, t: i64, elem: i64) -> i64 |
| 448 | func tc_open(c: *i64, st: *i64, d: i64, t: i64) -> i64 |
| 471 | func tc_skip(c: *i64, t: i64, st: *i64) -> i64 |
| 512 | func pq_le32(b: *u8, p: i64) -> i64 |
| 516 | func pq_bitwidth(maxv: i64) -> i64 called by 1: pq_read_column |
| 522 | func pq_fill(a: *i64, base: i64, n: i64, v: i64) -> i64 called by 1: pq_read_column |
| 527 | func pq_se(pq: *i64, i: i64) -> *i64 |
| 530 | func pq_rg(pq: *i64, r: i64) -> *i64 |
| 533 | func pq_cc(pq: *i64, r: i64, leaf: i64) -> *i64 |
| 537 | func pq_leaf_index(pq: *i64, leaf: i64) -> i64 |
| 549 | func pq_leaf_named(pq: *i64, s: *u8) -> i64 |
| 579 | func pq_parse_columnmeta(pq: *i64, c: *i64, st: *i64, cc: *i64) -> i64 |
| 614 | func pq_parse_columnchunk(pq: *i64, c: *i64, st: *i64, cc: *i64) -> i64 |
| 628 | func pq_parse_rowgroups(pq: *i64, c: *i64, st: *i64) -> i64 |
| 676 | func pq_schema_levels(pq: *i64) -> i64 |
| 718 | func pq_parse_schema(pq: *i64, c: *i64, st: *i64) -> i64 |
| 754 | func pq_parse_footer(pq: *i64) -> i64 |
| 780 | func pq_open(pq: *i64, path: *u8) -> i64 |
| 818 | func pq_parse_sub(c: *i64, st: *i64, ph: *i64, which: i64) -> i64 |
| 854 | func pq_parse_pageheader(pq: *i64, pos: i64, ph: *i64) -> i64 |
| 882 | func pq_snappy(src: *u8, s: i64, e: i64, out: *u8, o: i64, ocap: i64) -> i64 |
| 952 | func pq_inflate_page(pq: *i64, codec: i64, src: *u8, s: i64, e: i64, arena: *u8, a0: i64, acap: i64, usz: i64) -> i64 |
| 969 | func pq_hybrid(src: *u8, s: i64, e: i64, bw: i64, n: i64, out: *i64, cap: i64) -> i64 |
| 1028 | func pq_plain_bytes(arena: *u8, s: i64, e: i64, n: i64, off: *i64, len: *i64) -> i64 |
| 1045 | func pr_alloc(pq: *i64, r: i64, leaf: i64) -> *i64 |
| 1066 | func pr_free(pr: *i64) -> i64 |
| 1082 | func pq_read_column(pq: *i64, r: i64, leaf: i64, pr: *i64) -> i64 |
| 1261 | func pq_errname(rc: i64) -> *u8 |
| 1290 | func pq_tsv(pq: *i64, la: i64, lb: i64, out: *u8, stats: *i64) -> i64 |