Skip to content

feat(seql): scalable time-based analytics — bin N%, query templates, new aggregates - #16

Merged
Qard merged 11 commits into
mainfrom
feat/seql-analytics
Jul 28, 2026
Merged

Qard merged 11 commits into
mainfrom
feat/seql-analytics

Conversation

@Qard

@Qard Qard commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Extends SeQL so time-based query features scale to the query's time range and the range is a separable input (query templates), adds richer aggregation and window functions, wires the structured range end-to-end through the FFI + app, and teaches it all to the assistant. Implements the full analytics plan.

Stacked on #15 (feat/assistant-visualizations) — merge that first, or this rebases onto main once it lands.

Language (seql-ast / seql-parser / seql-substrait)

  • throughput() fixed (1c8251f) — real count(*) / seconds, per-bucket when time-bucketed else over the window; shared effective_window_ns.
  • Range-relative bucketing (cd08a18) — ts() bin 10% (~10 buckets of the window) and ts() bin auto (nice-snapped). A saved time-series re-buckets as the range changes.
  • Query templates (46d4e6d) — optional scan scope; compile_with_range/compile_ast_with_range inject a range that overrides the inline scope; scope-less + no range errors clearly.
  • New aggregates (d0edfe5) — stddev, variance/var, arbitrary percentile(col, q); p95/p99 refactored onto a shared helper.
  • Window functions (c3c2930) — window { moving_avg(col, n), cumulative(col), delta(col) } after aggregation, over DataFusion window frames (no lag UDF; delta via a [1 preceding,1 preceding] frame). A spike confirmed full Substrait round-trip through the backend's custom consumer, so no fallback is needed; live-safe via the existing Replace path.

Wiring (ffi + macOS)

  • Structured range through the FFI (7d2e2d7) — query_with_range/query_live_with_range on backend + client; C ABI sequins_seql_query[_live] gains (range_kind, range_a_ns, range_b_ns); header regenerated.
  • App passes the range structurally (68c9a06) — executeSeQL/executeLiveSeQL take an optional TimeRange; dashboards inject the picker's range (overriding the inline scope) instead of TimeRange.applied(to:) string rewriting — fixing the inner-scope / signal(id) gaps. Chat/one-off passes nil, honoring the inline scope.

Assistant (da52e91)

  • Grounding teaches percentile/stddev, corrected throughput, ts() bin 10%/auto, the window { … } stage, that dashboards apply the selected range automatically, and light interactive query-building guidance; parse-checked example list refreshed.

Testing

cargo test -p seql-ast -p seql-parser -p seql-substrait (26 / 114 / 44) — throughput scaling, bin 10%/auto, templates + injected-range override + no-range error, statistical aggregates, and a window query that compiles and consumes back through the backend's Substrait consumer. Grounding parse-check green. cargo fmt/clippy clean; FFI Rust builds, xcframework rebuilt, macOS app BUILD SUCCEEDED.

Note: for the new grounding to take effect in remote mode, the daemon container image needs rebuilding (grounding is compiled into the daemon).

🤖 Generated with Claude Code

Base automatically changed from feat/assistant-visualizations to main July 28, 2026 14:19
Qard and others added 10 commits July 28, 2026 22:20
…helper

throughput() was a stub returning count(*). Compute count(*) / seconds, where
seconds is the time-bin width when the query is bucketed by ts() (a per-bucket
rate) and otherwise the whole scan window — so the rate scales with the selected
time range. Adds effective_window_ns() and threads it through apply_aggregate,
laying groundwork for range-relative bucketing (ts() bin N%).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Introduce BinSpec (Fixed | Percent | Auto), replacing GroupExpr.bin_ns. The
compiler resolves Percent/Auto against the query's effective window at compile
time: `bin 10%` yields ~10 buckets scaled to the selected range, and `bin auto`
snaps to a nice duration ladder (~100 buckets). Fixed durations are unchanged.
This lets a saved time-series re-bucket sensibly as the dashboard range widens
or narrows instead of exploding a fixed `bin 1m` into thousands of buckets.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ime range

Make the scan time scope optional (Scan.time_range: Option<TimeRange>) so a
query can be a range-agnostic template (`spans | group by { ts() bin 10% } {
count() }`). Add compile_with_range / compile_ast_with_range that inject a
structured range which overrides any inline scope, so the dashboard's selected
range drives the whole query. A scope-less query on a time-scoped signal errors
if executed without a range instead of silently scanning everything. The
effective window (inline or injected) feeds bin N% / throughput, so time-relative
features scale to whatever range is applied.

Rust core only; FFI + Swift threading follows.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…ates

Add stddev(col), variance(col)/var(col), and percentile(col, q) — q a 0..1
quantile (a 0–100 form is normalized). p95/p99 now delegate to a shared
approx_percentile_cont helper, generalizing the previously hardcoded quantiles.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…a }`

Add a `window { … }` stage applied after aggregation over the ordered result
(by the ts() bucket / first temporal column): moving_avg(col, n), cumulative(col)
/running_sum(col), and delta(col) (period-over-period). Compiles to DataFusion
window exprs over row frames using only avg/sum UDAFs — delta reads the previous
row via a [1 preceding, 1 preceding] frame, so no lag UDF dependency.

A spike confirmed window functions survive the full Substrait round-trip through
the backend's custom consumer, so no SeqlExtension fallback is needed; a test
compiles a windowed time-series query and consumes it back to prove the daemon
can execute it. Being layered on aggregation, windowed queries are live-safe via
the existing Replace re-execution path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… path

Add query_with_range / query_live_with_range on the backend and client (compiling
via compile_*_with_range so a supplied range overrides the query's inline scope),
dispatch them through the FFI QueryExecutor, and extend the C ABI:
sequins_seql_query / _query_live now take (range_kind, range_a_ns, range_b_ns) —
kind 0=none, 1=relative sliding window (a=duration), 2=absolute (a=start,b=end).
Regenerates sequins.h. Lets the app run a scope-less query template against a
separately-chosen range instead of baking time into the query string.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…write

executeSeQL/executeLiveSeQL take an optional TimeRange, forwarded to the FFI as
the (range_kind, range_a_ns, range_b_ns) triple; dashboards now inject the
picker's range structurally (overriding the query's inline scope) instead of
rewriting the leading `<signal> <scope>` via TimeRange.applied(to:). This also
covers cases the string rewrite missed (inner sub-scopes, the signal(id)
shorthand) and lets a scope-less query template run against the selected range.
The chat/one-off path passes nil, so an inline scope is still honored.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Update default_grounding() to cover percentile/stddev/variance and the corrected
per-second throughput(), range-relative bucketing (ts() bin 10% / bin auto), and
the window { moving_avg, cumulative, delta } stage, plus a note that dashboards
apply the selected range/liveness automatically and light interactive
query-building guidance. Refresh the parse-checked example list accordingly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Superseded by query_with_range (the plain query() had no remaining callers).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Qard
Qard force-pushed the feat/seql-analytics branch from 10f4939 to c20190a Compare July 28, 2026 14:24
Rebasing onto main brought this branch's ABI change together with the test call
sites added by the assistant line (squashed into main as #15) for the first
time. Those tests call `sequins_seql_query` with the old 4-argument form, so
the crate fails to compile under `cargo test` — neither branch is broken alone.

Pass `0, 0, 0` (kind 0 = use the query's inline scope) at each of the 12 call
sites, preserving existing behavior.

Note this is invisible to CI's clippy step, which runs without --all-targets and
so never compiles test code; only the test step catches it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@Qard
Qard merged commit ba85ada into main Jul 28, 2026
3 checks passed
@Qard
Qard deleted the feat/seql-analytics branch July 28, 2026 16:31
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