Add an Arrow fast path for time-series transforms (MIN/MAX/AVG/SUM/TOP) #11

Open
opened 2026-10-21 12:54:01 +00:00 by aleksei · 0 comments
Owner

Context

The Arrow fast path (#9) covers raw PEEK queries (Query.transform == None) whose filter and sort use non-string columns. Queries with a transform still fall back to the row evaluator:

store::read_parts -> batch_to_rows -> serde_json::Value rows -> engine::transform_page.

For MIN, MAX, AVG, SUM and TOP on 100k+ rows this materialises and aggregates every row as JSON, so transforms are likely the slowest remaining read path in the local profile. ClickHouse computes them server-side from columnar storage.

Scope

Implement an Arrow/columnar fast path for the time-series transforms, preserving the ClickHouse-compatible semantics exactly:

MIN / MAX

  • Bucket on dateKey (default date) with floor(epoch_ms / interval) * interval, interval default 1 ms and at least 1.
  • Aggregate valueKey (default value) with min/max, ignoring nulls.
  • Output exactly { dateKey, valueKey }, date rendered canonically, sorted by the effective sort (default +dateKey), then offset/limit; total is the bucket count.

AVG / SUM

  • Keep the ClickHouse two-stage semantics: average valueKey per (id, bucket) first, then avg/sum those per-id averages per bucket.
  • Output exactly { dateKey, valueKey }, numeric result, canonical date, sorted and paginated; total is the bucket count.

TOP

  • Group by id, take the row with the maximum dateKey per id, output exactly { groupKey (default id), dateKey, valueKey } from that row.
  • Sort, offset/limit, total = group count.

General

  • Use Arrow compute kernels or columnar aggregation loops; do not materialise all rows as JSON. Format only the returned output rows.
  • Preserve dateKey/valueKey/groupKey resolution, interval, include/exclude (not applied to transform output, matching ClickHouse), null handling and deterministic tie behaviour.
  • Keep the existing row evaluator as the semantic reference and fallback for unsupported types (for example a non-numeric valueKey, unsupported group keys or a value type that cannot be aggregated). Add an equivalence test that runs the same transform through both paths.
  • If a transform cannot be supported safely, return the row path rather than changing results.

Acceptance criteria

  • Existing eve_e2e/tests/tsdb transform tests pass; add equivalence tests for MIN/MAX/AVG/SUM/TOP with nulls, multiple ids and non-default dateKey/valueKey/groupKey.
  • Add tsdb benchmark cases for transforms at 10k and 100k rows; document Parquet before/after and the comparison with ClickHouse.
  • total, output shape, date formatting and ordering match the row evaluator exactly.
  • cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test -p eve_tsdb_parquet, cargo test -p eve_e2e --test tsdb --test app pass.
  • adr/parquet.md documents the transform fast path and its fallback.

Non-goals

  • Changing the public API, on-disk format or provision semantics.
  • String/regex filters or string sort keys (they keep the row fallback).
  • Distributed execution; this is the local single-process profile.
## Context The Arrow fast path (#9) covers raw `PEEK` queries (`Query.transform == None`) whose filter and sort use non-string columns. Queries with a transform still fall back to the row evaluator: `store::read_parts` -> `batch_to_rows` -> `serde_json::Value` rows -> `engine::transform_page`. For `MIN`, `MAX`, `AVG`, `SUM` and `TOP` on 100k+ rows this materialises and aggregates every row as JSON, so transforms are likely the slowest remaining read path in the local profile. ClickHouse computes them server-side from columnar storage. ## Scope Implement an Arrow/columnar fast path for the time-series transforms, preserving the ClickHouse-compatible semantics exactly: ### MIN / MAX - Bucket on `dateKey` (default `date`) with `floor(epoch_ms / interval) * interval`, `interval` default 1 ms and at least 1. - Aggregate `valueKey` (default `value`) with min/max, ignoring nulls. - Output exactly `{ dateKey, valueKey }`, date rendered canonically, sorted by the effective sort (default `+dateKey`), then offset/limit; `total` is the bucket count. ### AVG / SUM - Keep the ClickHouse two-stage semantics: average `valueKey` per `(id, bucket)` first, then `avg`/`sum` those per-id averages per bucket. - Output exactly `{ dateKey, valueKey }`, numeric result, canonical date, sorted and paginated; `total` is the bucket count. ### TOP - Group by `id`, take the row with the maximum `dateKey` per id, output exactly `{ groupKey (default id), dateKey, valueKey }` from that row. - Sort, offset/limit, `total` = group count. ### General - Use Arrow compute kernels or columnar aggregation loops; do not materialise all rows as JSON. Format only the returned output rows. - Preserve `dateKey`/`valueKey`/`groupKey` resolution, `interval`, `include`/`exclude` (not applied to transform output, matching ClickHouse), null handling and deterministic tie behaviour. - Keep the existing row evaluator as the semantic reference and fallback for unsupported types (for example a non-numeric `valueKey`, unsupported group keys or a value type that cannot be aggregated). Add an equivalence test that runs the same transform through both paths. - If a transform cannot be supported safely, return the row path rather than changing results. ## Acceptance criteria - Existing `eve_e2e/tests/tsdb` transform tests pass; add equivalence tests for MIN/MAX/AVG/SUM/TOP with nulls, multiple ids and non-default `dateKey`/`valueKey`/`groupKey`. - Add `tsdb` benchmark cases for transforms at 10k and 100k rows; document Parquet before/after and the comparison with ClickHouse. - `total`, output shape, date formatting and ordering match the row evaluator exactly. - `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo test -p eve_tsdb_parquet`, `cargo test -p eve_e2e --test tsdb --test app` pass. - `adr/parquet.md` documents the transform fast path and its fallback. ## Non-goals - Changing the public API, on-disk format or provision semantics. - String/regex filters or string sort keys (they keep the row fallback). - Distributed execution; this is the local single-process profile.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
zoo/eve#11
No description provided.