-
Notifications
You must be signed in to change notification settings - Fork 25.7k
ESQL Fix bug when renaming @timestamp in TS queries #136062
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
|
Pinging @elastic/es-storage-engine (Team:StorageEngine) |
|
Hi @not-napoleon, I've created a changelog YAML for you. |
| } | ||
| if (attr.name().equals(MetadataAttribute.TIMESTAMP_FIELD)) { | ||
| timestamp.set(attr); | ||
| } |
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.
I consider it a happy bonus of this PR that we are no longer fishing out the timestamp as part of the translate rule. I wonder if we should do something similar for the TSID. It just seems wrong to be doing this here.
| * @param typeToken Only process expressions matching the given type | ||
| * @param rule a non-modifying consumer which operates on the given token type | ||
| * @param <E> the type of expression this pass will process | ||
| */ |
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.
I had to ask @fang-xing-esql how this worked, so I've written down what I learned from that conversation.
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.
I didn't add a randomized timestamp to the serialization tests because I expect that it won't be serialized.
|
Thank you Mark! The alias trick to get this working is clever. I tested the PR with several queries:
I also noticed that users can rename or drop
Thank you for your significant effort put into handling this case, but I wonder if we should provide a clearer error message rather than allowing the query to work in this way. What do you think? I'd also like to hear @kkrik-es's thoughts. |
…estamp' into ts-rename-timestamp
|
Hey, thanks for taking a look.
I think we need to fix this one. Otherwise we're leaking TS behavior out into non-TS mode. I should be able to do that after this merges (or if we decide we don't want this fix, I can cherry pick the bits I need)
This one seems more like something we shouldn't support. Renaming the timestamp kind of makes sense - the user might reference it elsewhere in the query - but in this case they're dropping a field that would only be included in the output if they included it themselves. I think we could error or silently ignore this safely. Another option would be to move the drop to after the stats. I don't love that, because it would have to be done in the analyzer phase, and that's not generally supposed to be moving nodes around as I understand it.
Yeah, I saw that we treat
Happy to help :) FWIW, I think we should fix this one. I'd like to hear from @alex-spies or @fang-xing-esql , but I think resolving the timestamp (and eventually _tsid) in the |
|
I don't think there is a use case for such queries; rather, we are fixing the generative queries. We could emit an error message like |
|
If It is an alternative option, it seems chasing down how the If we really want |
|
Thanks, Fang, for chiming in. For time-series queries to work properly, the timestamp and _tsid fields should not be manipulated; otherwise, the results could be incorrect or cause runtime errors. |
|
So, sounds like it's tricky to get aliases to work consistently. We should def catch the case where |
…#136231) Resolves #134994 After discussing this more on #136062, we have decided queries that rename the @timestamp field should fail with a clear error message. This relates to #136772 --------- Co-authored-by: elasticsearchmachine <[email protected]>
…elastic#136231) Resolves elastic#134994 After discussing this more on elastic#136062, we have decided queries that rename the @timestamp field should fail with a clear error message. This relates to elastic#136772 --------- Co-authored-by: elasticsearchmachine <[email protected]> Conflicts: x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java
…ueries (#136231) (#137112) * Return a better error message when Timestamp is renamed in TS queries (#136231) Resolves #134994 After discussing this more on #136062, we have decided queries that rename the @timestamp field should fail with a clear error message. This relates to #136772 --------- Co-authored-by: elasticsearchmachine <[email protected]> Conflicts: x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java * creating test analyzers is fragile apparently * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
|
Closing in favor of #136231 |
…elastic#136231) Resolves elastic#134994 After discussing this more on elastic#136062, we have decided queries that rename the @timestamp field should fail with a clear error message. This relates to elastic#136772 --------- Co-authored-by: elasticsearchmachine <[email protected]>
Resolves #134994
This PR addresses the issue with queries like
Here, the
rateaggregation function has an implied argument of@timestamp, but that field no longer exists when we get to the to the stats command. To solve this, we introduce a new specialization to theResolveRefsrule that finds the timestamp alias and plumbs it into theTimeSeriesAggregation. In addition to fixing the references for the implied arguments, it also sends the reference on as part of theTimeSeriesAggregationfor other use in theTranslateTimeSeriesAggregaterule.