Skip to content

fix: resolve null aggregates and broken time_bucket after SQL migration#16

Merged
farhan-syah merged 6 commits intomainfrom
fix/timeseries-aggregate-null-and-time-bucket
Apr 7, 2026
Merged

fix: resolve null aggregates and broken time_bucket after SQL migration#16
farhan-syah merged 6 commits intomainfrom
fix/timeseries-aggregate-null-and-time-bucket

Conversation

@farhan-syah
Copy link
Copy Markdown
Contributor

Summary

Fixes #15 — numeric aggregates (MIN/MAX/SUM/AVG) returning null and time_bucket() returning empty results after the nodedb-sql migration.

  • Aggregate field resolution: sql_plan_convert was passing the display alias (e.g. "MIN(elapsed_ms)") as the field name in (op, field) pairs instead of extracting the actual column name from the aggregate args. The executor then failed to find that column in the memtable, leaving accumulators empty → null. Added agg_expr_to_pair() helper and fixed all 3 call sites. This also fixes the cosmetic column naming issue (count_COUNT(all)count_all).
  • Interval parsing: parse_interval_to_ms only handled single-char suffixes (1h, 1m). Word-form intervals like '1 hour' were silently parsed as 0ms, disabling bucketing entirely. Rewrote to split on numeric/unit boundary and accept both short and word forms.

Test plan

  • cargo test -p nodedb-sql -- parse_intervals — unit tests for interval parsing (short + word forms)
  • SQL test suite (scripts/test.sh) — added timeseries aggregate coverage: individual and combined MIN/MAX/SUM/AVG, timestamp aggregates, GROUP BY + aggregates, WHERE + aggregates, time_bucket with 1h/1m intervals
  • All pre-existing SQL tests continue to pass

…dedb-sql migration

Fixes #15.

The aggregate executor receives (op, field) pairs but all three
PhysicalTask construction sites were passing the alias instead of the
source field name, so the executor could never locate the column and
returned null for every MIN/MAX/SUM/AVG result.

parse_interval_to_ms only handled compact suffixes ("1h", "15m") and
rejected the word-form intervals that DataFusion normalises SQL INTERVAL
literals into ("1 hour", "15 minutes"), causing time_bucket() to bucket
everything into epoch-zero and return an empty result set.

Changes:
- sql_plan_convert: extract agg_expr_to_pair() helper that reads the
  first argument expression (Column name or Wildcard) and use it at all
  three PhysicalTask construction sites instead of a.alias
- aggregate: extend parse_interval_to_ms to accept singular and plural
  word-form units (hour/hours, minute/minutes, second/seconds, day/days)
  alongside the existing compact forms; bare numbers are treated as
  seconds; unrecognised units return 0 instead of silently mis-routing
- aggregate: add unit tests covering word-form parsing
Fix rdkafka-sys build failure when compiling with --all-features by
adding the missing system libraries required for the Kafka client.
…in DEK encryption

Update encrypt_dek and decrypt_dek to use the non-deprecated Nonce::from
constructor. The decrypt path now performs an explicit TryInto conversion
to a [u8; 12] array before constructing the nonce, surfacing a proper
error if the slice length is wrong.
@farhan-syah farhan-syah merged commit 5783212 into main Apr 7, 2026
2 checks passed
@farhan-syah farhan-syah deleted the fix/timeseries-aggregate-null-and-time-bucket branch April 7, 2026 19:27
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.

Numeric aggregates (MIN/MAX/SUM/AVG) return null and time_bucket() returns empty after nodedb-sql migration

1 participant