-
Notifications
You must be signed in to change notification settings - Fork 25.6k
[ES|QL] TS Disallow renaming into timestamp prior to implicit use #137713
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
Changes from all commits
d38774b
97e53c0
0eb4a5b
d748fe5
27c236b
446cffd
80abab0
473184b
4a4c0e3
2623e7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| pr: 137713 | ||
| summary: TS Disallow renaming into timestamp prior to implicit use | ||
| area: ES|QL | ||
| type: bug | ||
| issues: | ||
| - 137655 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,9 +16,11 @@ | |
| import org.elasticsearch.xpack.esql.core.expression.Literal; | ||
| import org.elasticsearch.xpack.esql.core.expression.MetadataAttribute; | ||
| import org.elasticsearch.xpack.esql.core.expression.NamedExpression; | ||
| import org.elasticsearch.xpack.esql.core.tree.Node; | ||
| import org.elasticsearch.xpack.esql.core.type.DataType; | ||
| import org.elasticsearch.xpack.esql.core.util.CollectionUtils; | ||
| import org.elasticsearch.xpack.esql.core.util.Holder; | ||
| import org.elasticsearch.xpack.esql.expression.function.TimestampAware; | ||
| import org.elasticsearch.xpack.esql.expression.function.aggregate.AggregateFunction; | ||
| import org.elasticsearch.xpack.esql.expression.function.aggregate.DimensionValues; | ||
| import org.elasticsearch.xpack.esql.expression.function.aggregate.LastOverTime; | ||
|
|
@@ -240,6 +242,28 @@ protected LogicalPlan rule(TimeSeriesAggregate aggregate, LogicalOptimizerContex | |
| } | ||
| } | ||
| } | ||
| if (aggregate.child().output().contains(timestamp.get()) == false) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should run this check in TimeSeriesAggregate#postAnalysisVerification instead. What about TBucket? It seems we aren't checking it here.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh you're right; TBucket is a TimestampAware function so I thought it would be getting caught there but it doesn't end up in the list of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I rewrote it (edit: or so i thought; it didnt actually work) to be checked in TimeSeriesAggregate#postAnalysisVerification but it looks like something else actually catches the TBucket case already
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed, all the TimestampAware functions that are created by the Analyzer will have the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I guess we're doing this to prevent |
||
| var timestampAwareFunctions = timeSeriesAggs.keySet() | ||
| .stream() | ||
| .filter(ts -> ts instanceof TimestampAware) | ||
| .map(Node::sourceText) | ||
| .sorted() | ||
| .toList(); | ||
| if (timestampAwareFunctions.isEmpty() == false) { | ||
| int size = timestampAwareFunctions.size(); | ||
| throw new IllegalArgumentException( | ||
| "Function" | ||
| + (size > 1 ? "s " : " ") | ||
| + "[" | ||
| + String.join(", ", timestampAwareFunctions.subList(0, Math.min(size, 3))) | ||
| + (size > 3 ? ", ..." : "") | ||
| + "] require" | ||
| + (size > 1 ? " " : "s ") | ||
| + "a @timestamp field of type date or date_nanos to be present when run with the TS command, " | ||
| + "but it was not present." | ||
| ); | ||
| } | ||
| } | ||
| // time-series aggregates must be grouped by _tsid (and time-bucket) first and re-group by users key | ||
| List<Expression> firstPassGroupings = new ArrayList<>(); | ||
| firstPassGroupings.add(tsid.get()); | ||
|
|
||
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.
Why was this added? Is it necessary?
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.
It wasn't necessary but @bpintea recommended it in our conversation and I agreed it made sense to add
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.
@dnhatn wdyt?
If we want this, we'll have to update all time-series aggregate functions.
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'm not sure about the benefits of adding this, but I'm not against it either
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.
When seeing the failed query (in the issue this addresses), I wanted to quickly see what's happening in a running instance with debug on I hand running, but failed, because
@timestampisn't "visible". Since it's a parameter of the function, even if implicit, I think it can help. It's a nice to have though, not a strict necessity. And can be done here or some other PR.