Skip to content

fix: time_bucket() silently dropped from projections#18

Merged
farhan-syah merged 2 commits intomainfrom
fix/time-bucket-projection-drop
Apr 9, 2026
Merged

fix: time_bucket() silently dropped from projections#18
farhan-syah merged 2 commits intomainfrom
fix/time-bucket-projection-drop

Conversation

@farhan-syah
Copy link
Copy Markdown
Contributor

Summary

Fixes #17time_bucket() was silently dropped from projections after the nodedb-sql migration. All variants (alias, ordinal, swapped args, integer seconds, bare projection) now work correctly.

Root causes:

  • The nodedb-sql planner only recognized time_bucket() when it appeared literally as ast::Expr::Function in GROUP BY. SQL GROUP BY alias and GROUP BY 1 were treated as plain column names, so bucket_interval_ms stayed 0 and the Data Plane returned empty results.
  • extract_bucket_interval only handled time_bucket('interval', col) — not swapped arg order time_bucket(col, 'interval') or integer seconds time_bucket(3600, col).
  • Bare SELECT time_bucket(...) FROM t was silently dropped because the Timeseries scan path had no computed column support and time_bucket wasn't registered as an evaluable scalar function.

Changes:

  • nodedb-sql planner — Added resolve_group_by_expr() to resolve GROUP BY aliases/ordinals to their SELECT expressions before checking for time_bucket. Fixed extract_bucket_interval to handle both arg orders and integer-seconds form. Consolidated duplicate parse_interval_to_ms to use canonical nodedb_types::kv_parsing.
  • nodedb-query — Registered time_bucket as an evaluable scalar function in datetime.rs. Consolidated duplicate parse_interval_to_ms.
  • Timeseries Data Plane — Added computed_columns field to TimeseriesOp::Scan. Added RawScanParams struct. Applied computed column evaluation in raw scan path via apply_computed_columns_rmpv().
  • Pre-existing clippy fix in point.rs.

Test plan

  • All 6 reproduction queries from the issue return correct results
  • GROUP BY alias, GROUP BY 1, GROUP BY time_bucket(...) all resolve correctly
  • Swapped arg order time_bucket(timestamp, '1 hour') works
  • Integer seconds time_bucket(3600, timestamp) works
  • Bare SELECT time_bucket(...) FROM t LIMIT 3 returns bucketed timestamps (not SELECT *)
  • COUNT(*) baseline unaffected (100000)
  • All unit tests pass
  • Zero clippy warnings

Closes #17

…t detection

When a query uses GROUP BY with an alias (e.g. GROUP BY b) or a positional
ordinal (e.g. GROUP BY 1), the planner was failing to recognize the underlying
time_bucket() call, causing it to be misclassified as a plain group column.

Extract resolve_group_by_expr() to look up the originating SELECT expression
for alias and ordinal references, and try_extract_time_bucket() to isolate
the time_bucket detection logic. The GROUP BY loop now resolves before
checking, so all three forms — direct, alias, ordinal — correctly set the
bucket interval.
…jections

Add a computed_columns field to the timeseries physical plan node, allowing
scalar projection expressions (e.g. time_bucket) to be evaluated per-row
during raw scan execution.

- Propagate computed_columns bytes through the bridge plan, dispatch, and
  all plan construction sites (scan, aggregate, auto_tier, alert, native
  plan builder)
- Evaluate computed columns in the Data Plane raw scan handler by converting
  rmpv rows to nodedb_types::Value, applying expressions, and re-encoding
- Implement eval_time_bucket in the expression evaluator with support for
  both argument orders and integer-second intervals
- Replace the local parse_interval_to_ms implementation in nodedb-sql with
  a delegation to nodedb_types::kv_parsing::parse_interval_to_ms
- Refactor extract_bucket_interval to scan all arguments for the interval
  literal, enabling time_bucket with timestamp-first argument order
- Refactor raw_scan signature to use a RawScanParams struct
@farhan-syah farhan-syah merged commit 0c44334 into main Apr 9, 2026
0 of 2 checks passed
@farhan-syah farhan-syah deleted the fix/time-bucket-projection-drop branch April 9, 2026 09:06
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.

time_bucket() silently dropped from projections after nodedb-sql migration

1 participant