Skip to content

NDJSON output format with last-block tracking#9

Open
mo4islona wants to merge 1 commit into
masterfrom
ndjson-output
Open

NDJSON output format with last-block tracking#9
mo4islona wants to merge 1 commit into
masterfrom
ndjson-output

Conversation

@mo4islona

Copy link
Copy Markdown
Collaborator

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. JsonLinesWriter replaces JsonArrayWriter with the same buffering, only the framing differs.

execute_chunk_ext returns (writer, last_emitted_block); execute_chunk and execute_chunk_arrow become thin wrappers over it. run_query_ndjson is the worker-facing entry point: parse → scope to [from, to] → NDJSON plus the last block, None on 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 QueryOutput handle instead of a writer plus a returned cursor — and touches the same files. The two conflict; only one should land.

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>
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