refactor: evaluate Parquet queries on Arrow arrays #9

Merged
aleksei merged 1 commit from perf/parquet-arrow-query into main 2026-10-21 12:40:53 +00:00
Owner

Second step of the Parquet query optimization: add an Arrow compute fast path for raw queries. The benchmark tsdb query (10,000 rows, value=gt=5000, sort +date, limit 100) drops from ~4.88 ms on main to ~0.55 ms on a clean run (0.6–0.9 ms under host load), and ClickHouse is ~5.4–7.0 ms on the same workload.

What changed

engine::execute now tries fast::execute first; unsupported queries fall back to the unchanged JSON row evaluator, which remains the semantic reference.

Supported fast path: raw queries (transform == None) whose filter and sort touch only DateTime, Int64, Float64 and Boolean columns. It:

  • reads Arrow RecordBatches from the visible Parquet parts;
  • builds the FIQL mask with Arrow kernels (eq/neq/lt/le/gt/ge, Kleene and/or, is_null/is_not_null, in as an OR of equality);
  • filters batches with filter_record_batch and counts total from the masks;
  • sorts with lexsort_to_indices, appending the original row index as a stable tie-break, and uses limit = offset + limit for a top-k;
  • materialises only the returned page as JSON with canonical RFC 3339 dates.

Semantics preserved:

  • Ne with a null row / null literal matches the row evaluator (or(not(eq), is_null) / is_not_null);
  • nulls sort last in both directions;
  • Int64 is filtered and sorted through f64, exactly like filter::compare_values; a test around 2^53 proves the fast path and the row path agree;
  • string/JSON filters and sorts, regexes and transforms always fall back, so the case-insensitive collation and the transform semantics are untouched.

adr/parquet.md documents the fast path and the f64 integer rule. New e2e tests cover numeric/date filters, multi-field sorts with offset/limit, in, null sort order, null-ish literals, integer/boolean columns, and canonical date projection; the inline equivalence test runs supported queries through both paths and asserts identical items and totals.

Benchmarks (same machine, NATS + ClickHouse up, cargo bench -p eve_e2e -- tsdb)

Benchmark main this PR
tsdb query/parquet 4.88 ms 0.55 ms (clean; 0.6–0.9 ms loaded)
tsdb query/clickhouse 5.92 ms 5.4–7.0 ms (host load)
tsdb purge/parquet 1.74 ms 1.18–1.35 ms
tsdb persistent projection/parquet/100 10.20 ms 8.7–15.0 ms (load-dependent; the polling read is faster)
tsdb insert/parquet/1000 0.93 ms 0.87–0.97 ms
tsdb insert/parquet/1 0.17 ms 0.14–0.25 ms (load)

The clean 0.55 ms result is ~9x faster than main and ~10x faster than ClickHouse on this filtered/sorted page. Insert is untouched; the spread in the write/projection groups is host load.

Verification

cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test -p eve_tsdb_parquet                 # 22 passed
cargo test -p eve_e2e --test tsdb --test app    # 22 + 2 passed
RUSTDOCFLAGS="-D warnings" cargo doc -p eve_tsdb_parquet --no-deps
NATS_URL=nats://127.0.0.1:4222 \
CLICKHOUSE_URL=http://root:root1234@127.0.0.1:8123 \
  cargo bench -p eve_e2e -- tsdb

Not in this PR

Projection pushdown in read_batches, parallel part scans, a streaming top-k across parts, a fast path for string equality/sort, and a JSON-null literal in the FIQL parser remain follow-ups.

Second step of the Parquet query optimization: add an Arrow compute fast path for raw queries. The benchmark `tsdb query` (10,000 rows, `value=gt=5000`, sort `+date`, limit 100) drops from ~4.88 ms on `main` to **~0.55 ms** on a clean run (0.6–0.9 ms under host load), and ClickHouse is ~5.4–7.0 ms on the same workload. ## What changed `engine::execute` now tries `fast::execute` first; unsupported queries fall back to the unchanged JSON row evaluator, which remains the semantic reference. **Supported fast path:** raw queries (`transform == None`) whose filter and sort touch only `DateTime`, `Int64`, `Float64` and `Boolean` columns. It: - reads Arrow `RecordBatch`es from the visible Parquet parts; - builds the FIQL mask with Arrow kernels (`eq`/`neq`/`lt`/`le`/`gt`/`ge`, Kleene `and`/`or`, `is_null`/`is_not_null`, `in` as an OR of equality); - filters batches with `filter_record_batch` and counts `total` from the masks; - sorts with `lexsort_to_indices`, appending the original row index as a stable tie-break, and uses `limit = offset + limit` for a top-k; - materialises only the returned page as JSON with canonical RFC 3339 dates. **Semantics preserved:** - `Ne` with a null row / null literal matches the row evaluator (`or(not(eq), is_null)` / `is_not_null`); - nulls sort last in both directions; - `Int64` is filtered and sorted through `f64`, exactly like `filter::compare_values`; a test around 2^53 proves the fast path and the row path agree; - string/JSON filters and sorts, regexes and transforms always fall back, so the case-insensitive collation and the transform semantics are untouched. `adr/parquet.md` documents the fast path and the `f64` integer rule. New e2e tests cover numeric/date filters, multi-field sorts with offset/limit, `in`, null sort order, null-ish literals, integer/boolean columns, and canonical date projection; the inline equivalence test runs supported queries through both paths and asserts identical items and totals. ## Benchmarks (same machine, NATS + ClickHouse up, `cargo bench -p eve_e2e -- tsdb`) | Benchmark | main | this PR | |---|---:|---:| | `tsdb query/parquet` | 4.88 ms | **0.55 ms** (clean; 0.6–0.9 ms loaded) | | `tsdb query/clickhouse` | 5.92 ms | 5.4–7.0 ms (host load) | | `tsdb purge/parquet` | 1.74 ms | 1.18–1.35 ms | | `tsdb persistent projection/parquet/100` | 10.20 ms | 8.7–15.0 ms (load-dependent; the polling read is faster) | | `tsdb insert/parquet/1000` | 0.93 ms | 0.87–0.97 ms | | `tsdb insert/parquet/1` | 0.17 ms | 0.14–0.25 ms (load) | The clean 0.55 ms result is ~9x faster than `main` and ~10x faster than ClickHouse on this filtered/sorted page. Insert is untouched; the spread in the write/projection groups is host load. ## Verification ```sh cargo fmt --all -- --check cargo clippy --workspace --all-targets -- -D warnings cargo test -p eve_tsdb_parquet # 22 passed cargo test -p eve_e2e --test tsdb --test app # 22 + 2 passed RUSTDOCFLAGS="-D warnings" cargo doc -p eve_tsdb_parquet --no-deps NATS_URL=nats://127.0.0.1:4222 \ CLICKHOUSE_URL=http://root:root1234@127.0.0.1:8123 \ cargo bench -p eve_e2e -- tsdb ``` ## Not in this PR Projection pushdown in `read_batches`, parallel part scans, a streaming top-k across parts, a fast path for string equality/sort, and a JSON-null literal in the FIQL parser remain follow-ups.
aleksei deleted branch perf/parquet-arrow-query 2026-10-21 12:40:53 +00:00
Sign in to join this conversation.
No reviewers
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!9
No description provided.