diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java index a25ccdc58cf27..a54d87336a663 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizer.java @@ -117,10 +117,10 @@ public LogicalPlanOptimizer(LogicalOptimizerContext optimizerContext) { public LogicalPlan optimize(LogicalPlan verified) { var optimized = execute(verified); -// Failures failures = verifier.verify(optimized, verified.output()); -// if (failures.hasFailures()) { -// throw new VerificationException(failures); -// } + // Failures failures = verifier.verify(optimized, verified.output()); + // if (failures.hasFailures()) { + // throw new VerificationException(failures); + // } optimized.setOptimized(); return optimized; } diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/promql/PromqlLogicalPlanBuilder.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/promql/PromqlLogicalPlanBuilder.java index b98592dd68e1e..e766ab084b43a 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/promql/PromqlLogicalPlanBuilder.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/promql/PromqlLogicalPlanBuilder.java @@ -118,23 +118,24 @@ public LogicalPlan visitSelector(PromqlBaseParser.SelectorContext ctx) { throw new ParsingException(source(labelsCtx), "Vector selector must contain at least one non-empty matcher"); } } + final LabelMatchers matchers = new LabelMatchers(labels); + UnresolvedAttribute timestamp = new UnresolvedAttribute(source, MetadataAttribute.TIMESTAMP_FIELD); + Evaluation evaluation = visitEvaluation(ctx.evaluation()); - TimeValue range = visitDuration(ctx.duration()); - // TODO: TimeValue might not be needed after all - Expression rangeEx = new Literal(source(ctx.duration()), Duration.ofSeconds(range.getSeconds()), DataType.TIME_DURATION); // fall back to default if (evaluation == null) { evaluation = new Evaluation(start); } - - final LabelMatchers matchers = new LabelMatchers(labels); final Evaluation finalEvaluation = evaluation; + PromqlBaseParser.DurationContext duration = ctx.duration(); + if (duration == null) { + return new InstantSelector(source, series, labelExpressions, matchers, finalEvaluation, timestamp); + } + TimeValue range = visitDuration(duration); + // TODO: TimeValue might not be needed after all + Expression rangeEx = new Literal(source(duration), Duration.ofSeconds(range.getSeconds()), DataType.TIME_DURATION); - UnresolvedAttribute timestamp = new UnresolvedAttribute(source, MetadataAttribute.TIMESTAMP_FIELD); - - return range == null - ? new InstantSelector(source, series, labelExpressions, matchers, finalEvaluation, timestamp) - : new RangeSelector(source, series, labelExpressions, matchers, rangeEx, finalEvaluation, timestamp); + return new RangeSelector(source, series, labelExpressions, matchers, rangeEx, finalEvaluation, timestamp); } @Override diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/promql/PromqlCommand.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/promql/PromqlCommand.java index 64dbbbff5dbcc..6b549d980f63b 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/promql/PromqlCommand.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/promql/PromqlCommand.java @@ -102,9 +102,9 @@ public int hashCode() { public boolean equals(Object obj) { if (super.equals(obj)) { - PromqlCommand other = (PromqlCommand) obj; - return Objects.equals(child(), other.child()) && Objects.equals(promqlPlan, other.promqlPlan); - } + PromqlCommand other = (PromqlCommand) obj; + return Objects.equals(child(), other.child()) && Objects.equals(promqlPlan, other.promqlPlan); + } return false; } diff --git a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/promql/PromqlLogicalPlanOptimizerTests.java b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/promql/PromqlLogicalPlanOptimizerTests.java index a6539c6189638..0bac9c8ba15e5 100644 --- a/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/promql/PromqlLogicalPlanOptimizerTests.java +++ b/x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/promql/PromqlLogicalPlanOptimizerTests.java @@ -9,7 +9,6 @@ import org.elasticsearch.TransportVersion; import org.elasticsearch.index.IndexMode; -import org.elasticsearch.transport.Transport; import org.elasticsearch.xpack.esql.EsqlTestUtils; import org.elasticsearch.xpack.esql.action.EsqlCapabilities; import org.elasticsearch.xpack.esql.analysis.Analyzer; @@ -23,7 +22,6 @@ import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; import org.junit.BeforeClass; -import java.util.Collections; import java.util.Map; import static java.util.Collections.emptyMap;