Skip to content

fix: handle PromQL time binary aggregation#8398

Open
fengjiachun wants to merge 1 commit into
GreptimeTeam:mainfrom
fengjiachun:fix/promql-time-binary-aggregate
Open

fix: handle PromQL time binary aggregation#8398
fengjiachun wants to merge 1 commit into
GreptimeTeam:mainfrom
fengjiachun:fix/promql-time-binary-aggregate

Conversation

@fengjiachun

Copy link
Copy Markdown
Collaborator

What changed

  • Skip non-Greptime table scans when collecting PromQL row-key tag metadata.
  • Add regression coverage for sum/min/max/avg by (...) over time() - metric.

Why

Issue #8397 showed query_range returning 500 for aggregation over a binary expression involving time(). In v1.1.x, binary projections can retain __tsid for metric-engine optimization. The outer aggregate then inspects row-key metadata and may traverse the EmptyMetric dummy scan generated for time(), which is not backed by a Greptime table provider.

Validation

  • cargo fmt --check
  • cargo test -p query aggregate_over_binary_time_function_expr --lib -- --nocapture
  • cargo test -p query tsid --lib

Fixes #8397

@github-actions github-actions Bot added size/XS docs-not-required This change does not impact docs. labels Jul 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the PromQL planner in src/query/src/promql/planner.rs to handle derived PromQL plans that may contain non-Greptime scans without row-key metadata. It replaces the error propagation (?) with a conditional let Ok(table) check when retrieving a table from the source. Additionally, a new unit test aggregate_over_binary_time_function_expr has been added to verify aggregation behavior over binary time function expressions. I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Signed-off-by: jeremyhi <fengjiachun@gmail.com>
@fengjiachun fengjiachun force-pushed the fix/promql-time-binary-aggregate branch from eadc83d to a560200 Compare July 2, 2026 05:48
@fengjiachun fengjiachun marked this pull request as ready for review July 2, 2026 05:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-not-required This change does not impact docs. size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PromQL query_range returns 500 for min/max/avg/sum by (...) (time() - metric)

1 participant