NDJSON output format with last-block tracking#9
Open
mo4islona wants to merge 1 commit into
Open
Conversation
Make newline-delimited JSON the engine's default and only JSON output format, replacing the JSON-array writer. One block per line, a trailing newline, empty result -> empty output. NDJSON stays valid under byte-for-byte concatenation of per-chunk blobs, where a JSON array does not. - JsonLinesWriter replaces JsonArrayWriter (same buffering, line framing) - execute_chunk_ext returns (writer, last_emitted_block); execute_chunk and execute_chunk_arrow become thin wrappers - run_query_ndjson: parse -> scope to [from, to] -> NDJSON + last block (None on empty result, a safe inclusive resume cursor) - bundle the 7 dataset YAMLs: bundled_metadata(name) / supported_kinds() - e2e harness parses NDJSON; add value+framing parity tests vs the legacy engine (104 fixtures across 11 datasets, feature-gated) - parse NDJSON in the profile A/B bench and the arrow example Output is value-identical to the legacy engine; 143 lib + 132 e2e tests pass; latency unchanged (mean -0.9%, within noise). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
The worker needs newline-delimited JSON instead of a JSON array, and it needs to know the last block the engine actually wrote — the response can be trimmed to the size budget, so the queried range end is not a safe resume cursor.
NDJSON also survives byte-for-byte concatenation of per-chunk blobs, which a JSON array does not.
What changed
NDJSON is the engine's default and only JSON format: one block per line, trailing newline, empty result → empty output.
JsonLinesWriterreplacesJsonArrayWriterwith the same buffering, only the framing differs.execute_chunk_extreturns(writer, last_emitted_block);execute_chunkandexecute_chunk_arrowbecome thin wrappers over it.run_query_ndjsonis the worker-facing entry point: parse → scope to[from, to]→ NDJSON plus the last block,Noneon an empty result.The seven dataset YAMLs are bundled into the binary —
bundled_metadata(name)/supported_kinds()— so the worker doesn't ship a metadata directory.The e2e harness parses NDJSON, and a feature-gated parity suite compares value and framing against the legacy engine across 104 fixtures and 11 datasets.
Breaking
No engine API emits a JSON array anymore. Output is value-identical to the legacy engine, not byte-identical — field order differs and strings are raw UTF-8 — so consumers must compare parsed values.
Testing
142 lib + 132 e2e tests pass. Latency unchanged (mean −0.9%, within noise).
Relation to #8
#8 solves the same two problems with a different design — a lazily-encoded
QueryOutputhandle instead of a writer plus a returned cursor — and touches the same files. The two conflict; only one should land.