-
Notifications
You must be signed in to change notification settings - Fork 634
MQE: fix issue where queries containing a duplicate expression and timestamp()
produce incorrect results
#11830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
9aa5f2b
to
0a75c75
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for propagating timestamp()
through vector selectors to avoid incorrect deduplication, ensuring sample timestamps are returned when requested.
- Introduce a
ReturnSampleTimestamps
flag onVectorSelector
nodes and wire it through planning, execution, and serialization. - Update
Describe
,EquivalentTo
, andOperatorFactory
methods to account for the new flag. - Extend tests for vector selectors and common subexpression elimination to cover
timestamp()
scenarios and regenerate protobuf definitions.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
pkg/streamingpromql/planning/core/vector_selector.go | Support ReturnSampleTimestamps in Describe , EquivalentTo , and factory |
pkg/streamingpromql/planning/core/vector_selector_test.go | Add test cases for Describe and Equivalence with sample timestamps flag |
pkg/streamingpromql/planning/core/core.proto | Add returnSampleTimestamps field to VectorSelectorDetails |
pkg/streamingpromql/planning/core/core.pb.go | Regenerate protobuf code to handle the new field |
pkg/streamingpromql/planning.go | Mark ReturnSampleTimestamps on VectorSelector when planning timestamp() |
pkg/streamingpromql/optimize/plan/commonsubexpressionelimination/optimization_pass_test.go | Add CSE test scenarios involving timestamp() |
pkg/streamingpromql/operators/functions/factories.go | Remove redundant setter in TimestampFunctionOperatorFactory |
Comments suppressed due to low confidence (1)
pkg/streamingpromql/planning.go:324
- Add a unit test for
nodeFromExpr
to verify that parsingtimestamp(foo)
correctly setsReturnSampleTimestamps
on the resulting VectorSelector.
case "timestamp":
|
||
if isSelector { | ||
selector.ReturnSampleTimestamps = true | ||
// We'll have already set ReturnSampleTimestamps on the InstantVectorSelector during the planning process, so we don't need to do that here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This comment references the now-removed selector
variable and may confuse readers; consider updating or removing the outdated comment.
// We'll have already set ReturnSampleTimestamps on the InstantVectorSelector during the planning process, so we don't need to do that here. | |
// The ReturnSampleTimestamps property of InstantVectorSelector is set during the planning process, so no additional action is needed here. |
Copilot uses AI. Check for mistakes.
…imestamp()` produce incorrect results (#11830) #### What this PR does This PR fixes an issue in common subexpression elimination where an expression like `timestamp(foo_time) - foo_time` would produce incorrect results. This happens because the instant vector selector is incorrectly deduplicated in this case: at present, the instant vector selector operator behaves differently if it is wrapped in `timestamp()`, but the query planner did not take this into consideration when identifying duplicate expressions. A future improvement would be to allow the instant vector selector operator to return both the sample value and sample timestamp to different consumers, but given queries like this are rare, I've opted for the simpler approach. #### Which issue(s) this PR fixes or relates to #11189 #### Checklist - [x] Tests updated. - [n/a] Documentation added. - [covered by #10067] `CHANGELOG.md` updated - the order of entries should be `[CHANGE]`, `[FEATURE]`, `[ENHANCEMENT]`, `[BUGFIX]`. If changelog entry is not needed, please add the `changelog-not-needed` label to the PR. - [n/a] [`about-versioning.md`](https://github.com/grafana/mimir/blob/main/docs/sources/mimir/configure/about-versioning.md) updated with experimental features. (cherry picked from commit dd17406)
What this PR does
This PR fixes an issue in common subexpression elimination where an expression like
timestamp(foo_time) - foo_time
would produce incorrect results.This happens because the instant vector selector is incorrectly deduplicated in this case: at present, the instant vector selector operator behaves differently if it is wrapped in
timestamp()
, but the query planner did not take this into consideration when identifying duplicate expressions.A future improvement would be to allow the instant vector selector operator to return both the sample value and sample timestamp to different consumers, but given queries like this are rare, I've opted for the simpler approach.
Which issue(s) this PR fixes or relates to
#11189
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
. If changelog entry is not needed, please add thechangelog-not-needed
label to the PR.about-versioning.md
updated with experimental features.