Skip to content

Return lazily-encoded QueryOutput from the execute functions#8

Draft
kalabukdima wants to merge 1 commit into
masterfrom
query-output
Draft

Return lazily-encoded QueryOutput from the execute functions#8
kalabukdima wants to merge 1 commit into
masterfrom
query-output

Conversation

@kalabukdima

Copy link
Copy Markdown

Problem

Worker needs to know the last block that has been written. It also needs JSONL output instead of a JSON array. Modifying the interface to expose that information.

What changed

execute_plan / execute_chunk now return Result<Option<QueryOutput>>. QueryOutput exposes num_blocks / first_block / last_block immediately — block selection completes before any encoding — and encodes one block per write_next_block call. A streaming consumer holds at most one encoded block; buffering callers use into_json_lines(). None means the queried range doesn't intersect the chunk. The handle is fully owned: no lifetime parameter, and it stays valid after the chunk reader drops. The Arrow variants return Option<ArrowOutput> with the same block-range metadata.

Budget-trim bug fixed. The phase-1 scan optimization capped the item scan at the budget cutoff but left the block-header scan uncapped, so the range-end boundary block entered the output with unaccounted weight — inflating both the response and last_block. The header scan is now capped to the same cutoff, matching the non-optimized path.

Worker serializes responses as JSON Lines (matching the legacy engine's wire format — it previously sent a JSON array) and reports the engine's post-trim last_block, falling back to the range end only when the output is empty.

Breaking

Callers of execute_plan/execute_chunk/execute_plan_arrow must drop the writer argument and handle Option. No engine API emits a JSON array anymore.

Draft status

I still need to verify whether the ref cloning change doesn't affect the performance.

- Replace the writer-sink interface with Option<QueryOutput>: block range
  metadata is available up front, blocks encode one per write_next_block
  call, and framing (JSON lines, arrays) belongs to the caller
- Return Option<ArrowOutput> with the same block range metadata from the
  Arrow variants
- Cap the block header scan at the phase-1 budget cutoff so the range-end
  boundary block can't wrongly survive the response trim
- Cover budget trimming, boundary blocks, empty results and JSON/Arrow
  parity with synthetic-chunk tests

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kalabukdima
kalabukdima requested a review from mo4islona July 15, 2026 15:33
@kalabukdima kalabukdima self-assigned this Jul 15, 2026
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