Skip to content

The reference extractor reads Parquet as a table, its decimals exact - #269

Merged
zlareb1 merged 37 commits into
mainfrom
feat/parquet
Nov 5, 2026
Merged

zlareb1 merged 37 commits into
mainfrom
feat/parquet

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 5, 2026 •

Copy link
Copy Markdown
Member

Related: #157

Changelog category (leave one):

  • New Feature

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

The reference extractor reads Parquet files: each file becomes a table whose rows are searchable passages cited by row, and a typed dataset.

Why

The issue asks for Parquet next to CSV and XLSX as a tabular source for typed snapshots. The server already routed the format and refused it as format_unavailable; this PR adds the reader to the reference extractor, so a Parquet upload is ingested, searched and published as a dataset like the other tabular formats. Parquet needs a native decoder, so it comes in a change of its own, with its sandboxing measured.

Design

  • Reader (extractor/loom_extractor/parquetfile.py): pyarrow reads the file from the bytes in memory (BufferReader: no file system), with no threads (use_threads=False, one CPU and IO thread) and its system memory pool. The columns come from the schema, the first 16,384 kept by position, since a name may repeat (the rest are a failed unit, <name> columns); the rows a row group at a time in batches of at most 1,024 rows, sized so a batch's rows times leaf columns stay within the table budget's cells (MAX_CELLS); a list's elements are bounded by the decode bound below. It goes through the same tabular layer as CSV and XLSX (tabular.table), so the budget, the row blocks and the table are the same.
  • Values, decided once per column from the schema, so every batch of a column reads the same way:
    • An integer is a number. A decimal is a number written as its exact digits (never in exponent notation), because a JSON number reads back as a double; an integer past signed 64 bits (a uint64) is written the same way, so its column stays a number. The server's datasets read a number column's text as an exact Decimal.
    • A float is a number; a float32 or float16 column's value is its shortest decimal in its own type (0.1, not the double it widens to; the float32 maximum included), one inside a list or struct the double it widens to. A NaN is no value, as a null is (a dataframe writer's mark of a missing number), so a row of them is no row; an infinity is left out and counted (its sign with it), so a float column stays a number (read as text, one NaN would make its column mixed). As for any value left out, a file with an infinity ingests as partial only when the request allows it.
    • A bool, a date, a timestamp (its zone kept, none when the column has none), a time of day and a duration read as the other readers write them. A nanosecond unit is read to the microsecond, what Python's types and the dataset's DateTime64(6) hold, inside a list, struct or map too (a list view, which Arrow casts to no other element type, keeps its unit: a sub-microsecond value in it is left out and counted).
    • Text is text, a UUID its text (arrow.uuid, inside a list or struct too); a list, struct or map is its JSON (bytes inside it as base64, a value of a type JSON does not know as its text); a dictionary-encoded column is its values. Another extension type (arrow.opaque, a tensor) reads as what it stores, and a bool8 as a bool. A named time zone reads with the image's zone database (the base image ships one).
    • Bytes (binary, large_binary, fixed_size_binary, binary_view, an opaque extension over them) are no text: left out, never copied into Python, and counted as a failed unit (<name> values), as is an infinity, a value over 1,048,576 characters and a value Python cannot hold (a date past year 9999, a zone it does not know); a batch with such a value is split in halves until each part converts, so only that one is left out (about two conversions a halving for each such value), and past 16 of them in a column (across the file, not per batch) the rest of that column is left out unread, counted as such. The unit's reason names each cause and its count, over the rows read. A row of nulls, NaNs or blank text is no row, as a blank CSV record; a row whose values were all left out is still a row, counted.
    • A dataset's first 24 number or duration columns hold nine decimal places (Decimal128(9)), the rest a double (Float64), as for every format: a decimal(38,18) keeps every digit in the artifact and its passages and rounds at nine in its dataset. The feature and architecture pages say so.
  • No header row: the names are the schema's, no row of the file, so the table has header_rows 0 and its rows count from 1; its dataset asks no header_like_data question (a pivot export's 2023, 2024 columns are names, not a first row). tabular.Rows.header_row 0 says so; the contract page names header_rows 0, and the feature and architecture pages the question it skips.
  • Bounds: pages decode one at a time into batches no wider than the cell budget (by leaf columns), so neither a row group's size nor the file's width decides what is held, and the rows past the table budget are not read: those past the batch it ran out in, and past four million values or 256 MiB decoded or 100,000 row groups read (each costs a reader's setup), are counted from the metadata, never decoded. The decode bound is charged before a batch is read into Python, at least a value a row, every element of a list, struct or map down to its leaves (the columns past the bound too, since they are decoded), a dictionary entry (at any depth) once for each value that names it and a view value (string_view) once for each view that names its bytes (those two in a column read into Python: a bytes column is never copied), so a file of blank rows, of long lists or of long values is bounded too; the rows it cuts are a failed unit of their own (past what one file decodes), apart from the artifact's budget (past what one artifact holds). A decode that does not fit the child's memory (a list value past it) fails the rows from there as a decoder fault does. Coverage counts the row groups' rows, which is what the reader numbers. A row group whose pages do not decode, or hold more or fewer rows than its footer declares (rows are numbered and counted by the footer), fails the rows from there (<name> rows N-); a file pyarrow cannot open is corrupt. The extractor child's limits (address space, CPU, the socket filter) bound one decode.
  • Native libraries in the child: the child's environment holds Arrow to its system allocator (ARROW_DEFAULT_MEMORY_POOL), which the 1 GiB address-space limit allows, and OpenBLAS and OpenMP to one thread (OPENBLAS_NUM_THREADS, OMP_NUM_THREADS). The image has no numpy, but a development environment does, and there pyarrow loads it, whose per-thread buffer reservation fails under the limit without them.
  • Optional: the extractor declares Parquet only when pyarrow is installed (source.parsed_formats), so an image built without it reads every other format and the server reports Parquet format_unavailable, as for any format no extractor declares.
  • Dependency: pyarrow>=26,<27 in extractor/pyproject.toml (and the root extractor extra, for development and tests), locked in both lock files. The major is pinned because a major may change what its decoder accepts. It adds about 151 MB installed to the extractor image; the server's image carries none of it. pyarrow 26 needs no numpy.
  • knowledge.dataset_get writes a decimal's exact digits: Decimal.normalize() rounds to the default 28-digit context, which turned 99999999999999999999.123456789 into …12345679 (tests/unit/test_knowledge_datasets.py pins the digits).

Alternatives considered: a pure-Python Parquet reader (fewer native dependencies, but slow and narrower in encodings and types); converting to CSV in the extractor first (loses the types, decimals among them).

Security

pyarrow is native code parsing an uploaded file. It runs only in the extractor's per-extraction child: no network (the socket filter), no file it can write, root-owned code, an address-space and CPU limit, and no file system access from the reader (bytes in memory). Measured through the real child (seccomp filter and limits), each a single extraction:

Input Result
Compression bomb: 63 KB, 5,000,000 rows of 100 characters, dictionary-encoded 0.9 s; 63,675 rows kept, the rest a failed unit counted from the metadata
Plain-encoded row group declaring 520 MB uncompressed streams at 66 MB peak RSS; 0.9 s, cut at the budget
One column chunk of 936 MB uncompressed 0.9 s, cut at the budget
20,000 columns 0.7 s; 3,616 columns past the bound counted
16,384 columns × 1,024 rows 3.6 s; 60 rows kept (the cell budget), the rest counted
list<int8> bomb: 6.6 KB, 200 lists of 2,000,000 values 0.9 s; the allocation fails under the child's limit, the rows a failed unit (not decoded)
One struct of 100,000 leaf fields 2.0 s; the decoder's allocation fails under the limit, the rows a failed unit
Null-row bomb: 431 KB, 200,000,000 rows of nulls 2.5 s; decoded to four million values, each a blank cell, the rest counted from the metadata
500 columns × 2,000 rows, every value a date past year 9999 1.7 s; each value left out and counted, the search for them capped per column
16,384 columns × 250 rows, every value a date past year 9999 (the widest batch) 8.9 s; the search capped at 16 values a column across the file (a cap per batch instead measured 13.8 s)
1.7 KB: a dictionary of one 1.1 MB string, named by a third of 400,000 rows 0.3 s; the copies it would make are charged before any is made, past 256 MiB the rows counted (charging the dictionary once per batch instead measured 10.3 s)
29 KB: 20,000 rows, each a list of 175,000 nulls 0.5 s; the elements are charged before conversion, the rows past the decode bound counted
663 bytes: lists of a dictionary entry of 1.1 MB, 3,000 elements 0.3 s; a nested dictionary entry charged once per element
200,000 row groups of one row 4.6 s; cut at 100,000 rows
300,000 row groups of one null row (no other bound moves) 3.7 s; cut at 100,000 row groups read, the rest counted
A schema of lists nested 50 levels deep refused corrupt when opened (Arrow's schema depth limit)
300 byte-mutated copies of a mixed-type file (1-8 bytes each) 249 refused corrupt when opened, 51 extracted; no child crash, worst 0.2 s

Tests

  • Unit (tests/unit/test_document_extraction_parquet.py): every column type's value; values JSON cannot hold as numbers, a uint64 column, a NaN and an infinity keeping their column a number; the float32 maximum and small decimals in plain digits; nested values, bytes and binary_view left out and counted; row blocks cited by row and a row of nulls; rows past the budget counted from the metadata, not decoded (the decoded count asserted); a batch no wider than the cell budget; columns past the bound kept by position though a name repeats; nanosecond timestamps, times of day, durations and a nested list, large list, struct, map and dictionary of them read to the microsecond in every batch, a float16 column, a UUID (inside a list and a struct too) and a named zone; an opaque and a bool8 extension column; each cause of a value left out named, counted over the rows read, all five in full within a reason's 200 characters at the decode bound's counts; a block partly of rows left out holding only the rows with text, starting and ending at one; one value Python cannot hold left out of its batch alone, found by halves and capped per column across the file, one column's cap leaving another's values read; a file of blank rows (in one row group and across several), of long lists and of long values read only to the decode bound, its cut a failed unit of its own; a nested dictionary charged per element; a schema of no columns counted, not iterated (a footer may declare any row count); a batch of empty rows still charged a value a row; views sharing one buffer charged per view, a dictionary of views by its views' lengths; a bytes column and a column past the column bound charged no copies; a file of only blank rows, or of rows whose every value was left out, its header block at row 0, read back by the server and chunked; row groups past the bound counted, not read; a list of bool8 and a list view; a row of NaNs or blank text no row, one whose value was left out a row; a build without pyarrow imports, and neither parses nor declares Parquet; a date past year 9999 left out and counted; an unreadable file and a damaged later row group; the artifact read back by the server and typed as a dataset with exact decimals, its 2023, 2024 names asked no header question; a row count a footer declares below zero read as none, rows past signed 64 bits refused corrupt, and a row group whose pages hold more or fewer rows than its footer failed from there (the artifact never holds more rows than it declares).
  • Unit (tests/unit/test_extractor_service.py): a Parquet file read through the real child, under its limits and socket filter (it fails without the child's native-library environment).
  • Unit, updated: the tests that took Parquet as unparsed now name the case they mean, a build without pyarrow, or expect the reader's answer (corrupt for a file that is not Parquet); the service's capabilities and the quickstart smoke list Parquet; the child's environment allows the three native variables.
  • Unit (tests/unit/test_knowledge_datasets.py): a 38-digit decimal keeps every digit in dataset_get.
  • The lock files are written by the uv that wrote main's (lock revision 5).
  • Integration (tests/integration/test_knowledge_ingest_live.py) against a real server, ClickHouse and extractor: a Parquet upload is typed by its name, ingested, published as a dataset whose sample returns the exact decimal, and found by search with its row locator. Twelve tests passed; the leakage suites passed (42 passed, 17 skipped).
  • Full unit suite on the merged head: 27,504 passed, 19 skipped, 1 xfailed; the four cases of test_the_delimiter_is_sniffed_in_bounded_time (a CSV sniff under a 5 s wall-clock bound, code this PR does not touch) failed under load, as they do on main on the same machine.

🤖 Generated with Claude Code

@zlareb1
zlareb1 force-pushed the feat/parquet branch 2 times, most recently from c64571d to b8be536 Compare November 5, 2026 14:32
zlareb1 and others added 28 commits November 5, 2026 15:01
A Parquet file is read with pyarrow from the bytes in memory (no file
system, no threads, the system allocator) into one table and its rows as
passages; its datasets follow as for CSV and XLSX. A decimal is its exact
text, a uint64 past signed 64 bits its digits, a nested value its JSON;
bytes are left out and counted. Pages decode one at a time, the rows past
the budget are counted from the metadata, and the child's limits bound a
decode. A build without pyarrow does not declare Parquet. dataset_get keeps
every digit of a wide decimal.

Refs #157

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… by position

- A column's reading is decided from the schema: nanosecond units as
  microseconds (nested ones too), float16 as float32, so every batch reads
  alike; a uint64 past signed 64 bits and a decimal are a number's plain
  digits; a value Python cannot hold is left out and counted.
- The float32 maximum no longer refuses the file; binary_view is bytes.
- A batch holds no more cells than the budget, however wide the file; columns
  are kept by position; coverage counts the row groups' rows.
- Durations from their exact parts; source.py imports and errors tidied; the
  docs say a dataset holds a number to nine places; locks by main's uv.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…unction

- The architecture page, the contract page and the child's docstrings match
  the reader: nanoseconds to the microsecond, values Python cannot hold left
  out and counted, batches bounded by the cell budget, the native settings in
  the child's environment, a uint64 past int64 as exact digits.
- parsed_formats() decides what a build without pyarrow declares, tested
  directly; a nested float32 is the double it widens to, as documented.
- Tests: nanoseconds in a struct, map and dictionary, a float16 column, a
  UUID and a named zone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…lues still rows

- A batch holds no more values than the cell budget counted by leaf columns,
  so a wide struct no longer decodes past it; a decode the child's memory
  cannot hold fails its rows as a decoder fault does.
- A float16 is its shortest decimal in float16 (0.1, not 0.099975586).
- A row whose values were all left out is a row, counted; rows past the
  budget are not read for their values.
- Docs and docstrings reflowed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… microsecond

- A value Python cannot hold is LEFT_OUT, not a null, so a row of nothing
  else is still a row and stays in coverage.
- A fixed-size list of nanosecond values is cast to microseconds as other
  lists are; a MemoryError names itself in the failed unit; an unreachable
  budget check goes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- A UUID inside a list, struct or map is its text in the JSON (it refused the
  file); a value of a type JSON does not know is its text.
- An extension type other than a UUID reads as its storage, a bool8 as a
  bool, an opaque over bytes as bytes: left out, never copied into Python.
- A value left out is counted for the rows read only, its cause named.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… fails rows

- A value left out is counted for every row decoded, one rule for both
  budget cuts.
- A MemoryError from a cast (Arrow's too) fails the rows from there, as the
  decoder's does, instead of reading as values Python cannot hold.
- A list view keeps its stored type (Arrow casts it to no other element
  type); a list of bool8 reads as bools; type checks use is not None.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…k no header question

- A batch whose column holds a value Python cannot hold is converted a value
  at a time, so only that value is left out and the count is exact.
- A table with no header row (a Parquet schema's names) gets no
  header_like_data clarification.
- Docs say the rows past the budget are not read; tests cover a list view's
  sub-microsecond value, a list of float16 and an Arrow MemoryError in a
  conversion.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- At most four million values are decoded, blank rows' included, so a file
  of nulls is read only that far; the rest is counted from the metadata.
- A batch with a value Python cannot hold is split in halves until each part
  converts, so k such values cost about k log n conversions, and past 16 the
  rest of that batch's column is left out unread.
- One MemoryError guard; docs and docstring updated; tests for both bounds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…t names it

- A batch's logical bytes (its buffers, and a string or binary dictionary's
  entries for each row that names them, the copies Python makes) count
  against 256 MiB decoded, before any value is converted; past it, the rest
  is counted from the metadata. A 1.7 KB file naming one 1.1 MB entry from a
  third of 400,000 rows stops in 0.2 s, not 10.3.
- Values left out unread past the per-batch cap have a cause of their own.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…is its own unit

- The decode bound charges a batch's every element, a list, struct or map
  down to its leaves, and a dictionary at any depth once for each value that
  names it, before the batch is read into Python: a 29 KB file of lists of
  175,000 nulls stops in 0.5 s, a 663-byte file of lists of a 1.1 MB entry
  in 0.3 s.
- The rows the decode bound cuts are a failed unit of their own, "past what
  one file decodes", apart from the artifact's budget.
- The left-out sentinels are private.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ot iterated

- The decode bound charges at least a value a row, so rows with no values
  (no column, or none decoded) still move it.
- A schema of no columns has only blank rows, counted from the metadata
  without a read, since a footer may declare any row count; a row group of
  no rows sets up no reader.
- A string_view or binary_view dictionary's copies are charged too; the
  predicates read as tuples; the columns past MAX_COLUMNS are charged, as
  they are decoded.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- Past 100,000 row groups read (each costs a reader's setup, whatever it
  holds), the rest is counted from the metadata: 300,000 one-row groups of
  nulls stop in 3.5 s.
- A view array's values beyond its data buffers (views sharing one buffer)
  are charged once per view, read from the view buffer without a copy.
- The Table docstring names Parquet and header_rows 0.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
- The 16 values Python cannot hold that a column is searched for count
  across its batches, so a wide file of them is searched once, not per
  batch: 16,384 columns of dates past year 9999 take 8.9 s, not 13.8.
- A view array with no view buffer costs nothing; the module docstring
  names the row-group bound.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…ts without pyarrow

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…child in a test

The ingest test's fake Parquet file is now corrupt, not unavailable; the docs
say a dataset's first 24 number columns hold nine places, the rest doubles.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…column stays a number

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…text is no row

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… values as they go

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…tes column

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…et files

A row count a footer declares below zero is no rows; a Parquet file's numeric
names are asked no header question, end to end.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… across them

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…wrapped lines

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
… its rows

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 4 commits November 5, 2026 15:01
A runaway decode is refused at the time limit; the Parquet tests import
pyarrow, which every test environment installs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…footer

The rows are numbered and counted by the footer, so an artifact never holds
more rows than its coverage declares.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
zlareb1 and others added 5 commits November 5, 2026 15:12
A Parquet file whose every value was left out is then a source to find, not
a no_text failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…hin a reason

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
…lue is past

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 merged commit 24b619c into main Nov 5, 2026
22 of 24 checks passed
@zlareb1
zlareb1 deleted the feat/parquet branch November 5, 2026 16:24
@zlareb1 zlareb1 mentioned this pull request Nov 12, 2026
3 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant