Skip to content

refactor(query-engine): add Scalar and Table QueryResult variants - #938

Draft
milindsrivastava1997 wants to merge 1 commit into
refactor/query-requestfrom
refactor/query-result-variants
Draft

milindsrivastava1997 wants to merge 1 commit into
refactor/query-requestfrom
refactor/query-result-variants

Conversation

@milindsrivastava1997

@milindsrivastava1997 milindsrivastava1997 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Plan step 3 of .design_docs/asapplanner-engine-boundaries.md, stacked on #937 (step 2) and #936 (step 1).

Change

  • QueryResult gains Scalar(Sample), one timestamped value (the PromQL scalar), and Table(Table { columns, rows }), where cells are TableValue::{String, Float}. Table::is_rectangular() checks that every row has one value per column.
  • QueryResultType (promql_utilities) gains Scalar and Table, so QueryResult::result_type() stays total.
  • Each response adapter formats what its protocol can express and errors on the rest:
Adapter Vector Matrix Scalar Table
Prometheus instant (convert_query_result_to_prometheus) as before error → 500 (as before) {"resultType":"scalar","result":[ts,"v"]} error → 500
Prometheus range (convert_range_result_to_prometheus) error → 500 (as before) as before error → 500 error → 500
ClickHouse (TSV) as before 501 (as before) 501 one tab-separated line per row
Elastic (hits) as before 501 (as before) 501 one hit per row, _source keyed by column

A non-rectangular Table returns a 500 from ClickHouse and Elastic; it is never formatted after silently truncating or padding rows.

Scope choices to review

  • Prometheus formats Scalar rather than erroring. It is a native Prometheus result type, the formatting is fixed by the protocol, and new engines will produce it for scalar(...) and numeric literals. Erroring instead is a one-line change.
  • Table cells are String | Float. That covers today's SQL flattening (label values plus one value). Add more types when an engine produces them. The real cell types (ints, NULLs, bools from the executor's Arrow batches) are revisited when the executor result is converted to QueryResult, in the executor QueryEngine / wiring steps.

Behavior

No change: nothing produces Scalar or Table yet, and the Vector/Matrix paths are untouched.

Tests

  • New, 9 tests: Prometheus scalar formatting; Prometheus rejects Table (instant) and Scalar/Table (range); ClickHouse and Elastic format Table, return 500 for a ragged table, and return 501 for Scalar.
  • Changed beyond imports: 9 test-helper matches on QueryResult (stage_e_instant_range_equivalence_tests, one simple_engine test helper, e2e_precompute_equivalence) gain an other => panic!(..) arm so they stay exhaustive. Their existing arms are untouched.
  • cargo fmt, cargo clippy --workspace --all-targets --all-features -D warnings and cargo test --workspace --locked pass: 1546 passed (1537 + 9).

🤖 Generated with Claude Code

QueryResult gains Scalar (one timestamped value) and Table {columns,
rows}. Response adapters format what their protocol can express and
error on the rest: Prometheus formats Scalar as resultType "scalar" and
rejects Table; ClickHouse (TSV) and Elastic (hits) format Table and
return NOT_IMPLEMENTED for Scalar, as they do for Matrix. A table whose
rows don't match its columns is a 500, not silently truncated.

Nothing produces the new variants yet. Exhaustive test matches gain a
panic arm for them.

Co-Authored-By: Claude Opus 5.5 <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