-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Translate start/end to filter on @timestamp
#138412
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
5949a51
6f88cf7
0c72e0f
87d11d8
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 |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| import org.elasticsearch.xpack.esql.analysis.Analyzer; | ||
| import org.elasticsearch.xpack.esql.analysis.AnalyzerContext; | ||
| import org.elasticsearch.xpack.esql.core.expression.Alias; | ||
| import org.elasticsearch.xpack.esql.core.expression.FieldAttribute; | ||
| import org.elasticsearch.xpack.esql.core.expression.FoldContext; | ||
| import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RegexMatch; | ||
| import org.elasticsearch.xpack.esql.core.tree.Source; | ||
|
|
@@ -41,7 +42,6 @@ | |
| import java.time.Duration; | ||
| import java.time.Instant; | ||
| import java.time.temporal.ChronoUnit; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
|
|
||
|
|
@@ -57,8 +57,6 @@ | |
| // @TestLogging(value = "org.elasticsearch.xpack.esql:TRACE", reason = "debug tests") | ||
| public class PromqlLogicalPlanOptimizerTests extends AbstractLogicalPlanOptimizerTests { | ||
|
|
||
| private static final String PARAM_FORMATTING = "%1$s"; | ||
|
|
||
| private static Analyzer tsAnalyzer; | ||
|
|
||
| @BeforeClass | ||
|
|
@@ -93,7 +91,6 @@ public void testExplainPromql() { | |
| ) | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
| } | ||
|
|
||
| public void testExplainPromqlSimple() { | ||
|
|
@@ -106,7 +103,6 @@ public void testExplainPromqlSimple() { | |
| | STATS AVG(AVG_OVER_TIME(network.bytes_in)) BY TBUCKET(1h) | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -144,8 +140,6 @@ public void testAvgAvgOverTimeOutput() { | |
| | LIMIT 1000 | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
|
|
||
| var project = as(plan, Project.class); | ||
| assertThat(project.projections(), hasSize(3)); | ||
|
|
||
|
|
@@ -240,7 +234,6 @@ public void testTSAvgAvgOverTimeOutput() { | |
| | LIMIT 1000 | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -270,9 +263,6 @@ public void testTSAvgWithoutByDimension() { | |
| | STATS avg(avg_over_time(network.bytes_in)) BY TBUCKET(1h) | ||
| | LIMIT 1000 | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
|
|
||
| } | ||
|
|
||
| /** | ||
|
|
@@ -306,7 +296,6 @@ public void testPromqlAvgWithoutByDimension() { | |
| | LIMIT 1000 | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -337,7 +326,6 @@ public void testRangeSelector() { | |
| | promql step 1h ( max by (pod) (avg_over_time(network.bytes_in[1h])) ) | ||
| """); | ||
|
|
||
| logger.trace(plan); | ||
| } | ||
|
|
||
| @AwaitsFix(bugUrl = "Invalid call to dataType on an unresolved object ?RATE_$1") | ||
|
|
@@ -353,7 +341,6 @@ avg by (pod) (rate(network.bytes_in[1h])) | |
| """; | ||
|
|
||
| var plan = planPromql(testQuery); | ||
| logger.trace(plan); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -385,8 +372,10 @@ public void testStartEndStep() { | |
| """; | ||
|
|
||
| var plan = planPromql(testQuery); | ||
| List<LogicalPlan> collect = plan.collect(Bucket.class::isInstance); | ||
| logger.trace(plan); | ||
| var filters = plan.collect(Filter.class::isInstance); | ||
| assertThat(filters, hasSize(1)); | ||
| var filter = (Filter) filters.getFirst(); | ||
| assertThat(filter.condition().collect(e -> e instanceof FieldAttribute a && a.name().equals("@timestamp")), hasSize(2)); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -427,7 +416,6 @@ max by (pod) (avg_over_time(network.bytes_in{pod=~"host-0|host-1|host-2"}[5m])) | |
| assertThat(filters, hasSize(1)); | ||
| var filter = (Filter) filters.getFirst(); | ||
| assertThat(filter.condition().anyMatch(In.class::isInstance), equalTo(true)); | ||
| logger.trace(plan); | ||
| } | ||
|
|
||
| public void testLabelSelectorPrefix() { | ||
|
|
@@ -448,7 +436,6 @@ avg by (pod) (avg_over_time(network.bytes_in{pod=~"host-.*"}[5m])) | |
| var filter = (Filter) filters.getFirst(); | ||
| assertThat(filter.condition().anyMatch(StartsWith.class::isInstance), equalTo(true)); | ||
| assertThat(filter.condition().anyMatch(NotEquals.class::isInstance), equalTo(false)); | ||
| logger.trace(plan); | ||
| } | ||
|
|
||
| public void testLabelSelectorProperPrefix() { | ||
|
|
@@ -518,7 +505,6 @@ sum by (host.name, mountpoint) (last_over_time(system.filesystem.usage{state=~"u | |
| """; | ||
|
|
||
| var plan = planPromql(testQuery); | ||
| logger.trace(plan); | ||
| } | ||
|
|
||
| @AwaitsFix(bugUrl = "only aggregations across timeseries are supported at this time (found [foo or bar])") | ||
|
|
@@ -539,7 +525,6 @@ public void testGrammar() { | |
| """; | ||
|
|
||
| var plan = planPromql(testQuery); | ||
| logger.trace(plan); | ||
| } | ||
|
|
||
| // public void testPromqlArithmetricOperators() { | ||
|
|
@@ -567,9 +552,9 @@ protected LogicalPlan planPromql(String query) { | |
| query = query.replace("$now-1h", '"' + Instant.now().minus(1, ChronoUnit.HOURS).toString() + '"'); | ||
| query = query.replace("$now", '"' + Instant.now().toString() + '"'); | ||
| var analyzed = tsAnalyzer.analyze(parser.createStatement(query)); | ||
| logger.trace(analyzed); | ||
| logger.trace("analyzed plan:\n{}", analyzed); | ||
|
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. Remove? Or set to
Member
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 think the trace level is fine to be able to debug/inspect the plan during testing. I've removed the redundant |
||
| var optimized = logicalOptimizer.optimize(analyzed); | ||
| logger.trace(optimized); | ||
| logger.trace("optimized plan:\n{}", optimized); | ||
| return optimized; | ||
| } | ||
| } | ||
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.
Shouldn't we have 2?
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.
There's one filter with multiple conditions (metric not null, timestamp >= start, timestamp <= end)
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've adjusted the assertion in 6f88cf7 to check that there are two conditions for
@timestamp.