Repository navigation
The reference extractor reads Parquet as a table, its decimals exact - #269
Merged
Merged
Conversation
zlareb1
force-pushed
the
feat/parquet
branch
2 times, most recently
from
November 5, 2026 14:32
c64571d to
b8be536
Compare
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]>
…column 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]>
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]>
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]>
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]>
…ad as 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]>
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]>
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]>
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #157
Changelog category (leave one):
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
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.uint64) is written the same way, so its column stays a number. The server's datasets read a number column's text as an exactDecimal.float32orfloat16column'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.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).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 abool8as a bool. A named time zone reads with the image's zone database (the base image ships one).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.Decimal128(9)), the rest a double (Float64), as for every format: adecimal(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.header_rows0 and its rows count from 1; its dataset asks noheader_like_dataquestion (a pivot export's2023,2024columns are names, not a first row).tabular.Rows.header_row0 says so; the contract page namesheader_rows0, and the feature and architecture pages the question it skips.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 iscorrupt. The extractor child's limits (address space, CPU, the socket filter) bound one decode.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.source.parsed_formats), so an image built without it reads every other format and the server reports Parquetformat_unavailable, as for any format no extractor declares.pyarrow>=26,<27inextractor/pyproject.toml(and the rootextractorextra, 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_getwrites a decimal's exact digits:Decimal.normalize()rounds to the default 28-digit context, which turned99999999999999999999.123456789into…12345679(tests/unit/test_knowledge_datasets.pypins 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:
list<int8>bomb: 6.6 KB, 200 lists of 2,000,000 valuesnot decoded)corruptwhen opened (Arrow's schema depth limit)corruptwhen opened, 51 extracted; no child crash, worst 0.2 sTests
tests/unit/test_document_extraction_parquet.py): every column type's value; values JSON cannot hold as numbers, auint64column, a NaN and an infinity keeping their column a number; the float32 maximum and small decimals in plain digits; nested values, bytes andbinary_viewleft 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, afloat16column, a UUID (inside a list and a struct too) and a named zone; an opaque and abool8extension 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 ofbool8and 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, its2023,2024names asked no header question; a row count a footer declares below zero read as none, rows past signed 64 bits refusedcorrupt, 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).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).corruptfor 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.tests/unit/test_knowledge_datasets.py): a 38-digit decimal keeps every digit indataset_get.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).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 onmainon the same machine.🤖 Generated with Claude Code