Skip to content

Commit 7875826

Browse files
committed
Fix for instant selector queries
Accounts for ctx.duration() returning null
1 parent c602a60 commit 7875826

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/promql/LogicalPlanBuilder.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,24 @@ public LogicalPlan visitSelector(PromqlBaseParser.SelectorContext ctx) {
118118
throw new ParsingException(source(labelsCtx), "Vector selector must contain at least one non-empty matcher");
119119
}
120120
}
121+
final LabelMatchers matchers = new LabelMatchers(labels);
122+
UnresolvedAttribute timestamp = new UnresolvedAttribute(source, MetadataAttribute.TIMESTAMP_FIELD);
123+
121124
Evaluation evaluation = visitEvaluation(ctx.evaluation());
122-
TimeValue range = visitDuration(ctx.duration());
123-
// TODO: TimeValue might not be needed after all
124-
Expression rangeEx = new Literal(source(ctx.duration()), Duration.ofSeconds(range.getSeconds()), DataType.TIME_DURATION);
125125
// fall back to default
126126
if (evaluation == null) {
127127
evaluation = new Evaluation(start);
128128
}
129-
130-
final LabelMatchers matchers = new LabelMatchers(labels);
131129
final Evaluation finalEvaluation = evaluation;
130+
PromqlBaseParser.DurationContext duration = ctx.duration();
131+
if (duration == null) {
132+
return new InstantSelector(source, series, labelExpressions, matchers, finalEvaluation, timestamp);
133+
}
134+
TimeValue range = visitDuration(duration);
135+
// TODO: TimeValue might not be needed after all
136+
Expression rangeEx = new Literal(source(duration), Duration.ofSeconds(range.getSeconds()), DataType.TIME_DURATION);
132137

133-
UnresolvedAttribute timestamp = new UnresolvedAttribute(source, MetadataAttribute.TIMESTAMP_FIELD);
134-
135-
return range == null
136-
? new InstantSelector(source, series, labelExpressions, matchers, finalEvaluation, timestamp)
137-
: new RangeSelector(source, series, labelExpressions, matchers, rangeEx, finalEvaluation, timestamp);
138+
return new RangeSelector(source, series, labelExpressions, matchers, rangeEx, finalEvaluation, timestamp);
138139
}
139140

140141
@Override

0 commit comments

Comments
 (0)