Skip to content

Commit 3f21d1f

Browse files
committed
Merge branch 'esql/promql' into promql-fix-instant-queries
2 parents 930956b + d44915b commit 3f21d1f

File tree

6 files changed

+35
-35
lines changed

6 files changed

+35
-35
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,8 @@ public PlanFactory visitSampleCommand(EsqlBaseParser.SampleCommandContext ctx) {
11461146
public PlanFactory visitPromqlCommand(EsqlBaseParser.PromqlCommandContext ctx) {
11471147
Source source = source(ctx);
11481148
Map<String, Expression> params = new HashMap<>();
1149-
String TIME = "time", START = "start", STOP = "stop", STEP = "step";
1150-
Set<String> allowed = Set.of(TIME, START, STOP, STEP);
1149+
String TIME = "time", START = "start", END = "end", STEP = "step";
1150+
Set<String> allowed = Set.of(TIME, START, END, STEP);
11511151

11521152
if (ctx.promqlParam().isEmpty()) {
11531153
throw new ParsingException(source(ctx), "Parameter [{}] or [{}] is required", STEP, TIME);
@@ -1175,21 +1175,21 @@ public PlanFactory visitPromqlCommand(EsqlBaseParser.PromqlCommandContext ctx) {
11751175
// Validation logic for time parameters
11761176
Expression time = params.get(TIME);
11771177
Expression start = params.get(START);
1178-
Expression stop = params.get(STOP);
1178+
Expression end = params.get(END);
11791179
Expression step = params.get(STEP);
11801180

1181-
if (time != null && (start != null || stop != null || step != null)) {
1181+
if (time != null && (start != null || end != null || step != null)) {
11821182
throw new ParsingException(
11831183
source,
11841184
"Specify either [{}] for instant query or [{}}], [{}] or [{}}] for a range query",
11851185
TIME,
11861186
STEP,
11871187
START,
1188-
STOP
1188+
END
11891189
);
11901190
}
1191-
if ((start != null || stop != null) && step == null) {
1192-
throw new ParsingException(source, "[{}}] is required alongside [{}}] or [{}}]", STEP, START, STOP);
1191+
if ((start != null || end != null) && step == null) {
1192+
throw new ParsingException(source, "[{}}] is required alongside [{}}] or [{}}]", STEP, START, END);
11931193
}
11941194

11951195
// TODO: Perform type and value validation
@@ -1220,7 +1220,7 @@ public PlanFactory visitPromqlCommand(EsqlBaseParser.PromqlCommandContext ctx) {
12201220

12211221
return plan -> time != null
12221222
? new PromqlCommand(source, plan, promqlPlan, time)
1223-
: new PromqlCommand(source, plan, promqlPlan, start, stop, step);
1223+
: new PromqlCommand(source, plan, promqlPlan, start, end, step);
12241224
}
12251225

12261226
private static ParsingException getParsingException(ParsingException pe, int promqlStartLine, int promqlStartColumn) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,21 @@ public LogicalPlan createStatement(String query) {
4949
return createStatement(query, null, null);
5050
}
5151

52-
public LogicalPlan createStatement(String query, Instant start, Instant stop) {
52+
public LogicalPlan createStatement(String query, Instant start, Instant end) {
5353
if (log.isDebugEnabled()) {
5454
log.debug("Parsing as expression: {}", query);
5555
}
5656

5757
if (start == null) {
5858
start = Instant.now(UTC);
5959
}
60-
return invokeParser(query, start, stop, PromqlBaseParser::singleStatement, PromqlAstBuilder::plan);
60+
return invokeParser(query, start, end, PromqlBaseParser::singleStatement, PromqlAstBuilder::plan);
6161
}
6262

6363
private <T> T invokeParser(
6464
String query,
6565
Instant start,
66-
Instant stop,
66+
Instant end,
6767
Function<PromqlBaseParser, ParserRuleContext> parseFunction,
6868
BiFunction<PromqlAstBuilder, ParserRuleContext, T> visitor
6969
) {
@@ -97,7 +97,7 @@ private <T> T invokeParser(
9797
if (log.isTraceEnabled()) {
9898
log.trace("Parse tree: {}", tree.toStringTree());
9999
}
100-
return visitor.apply(new PromqlAstBuilder(start, stop), tree);
100+
return visitor.apply(new PromqlAstBuilder(start, end), tree);
101101
} catch (StackOverflowError e) {
102102
throw new ParsingException(
103103
"PromQL statement is too large, causing stack overflow when generating the parsing tree: [{}]",

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,20 +74,20 @@
7474

7575
class ExpressionBuilder extends IdentifierBuilder {
7676

77-
protected final Instant start, stop;
77+
protected final Instant start, end;
7878

7979
ExpressionBuilder() {
8080
this(null, null);
8181
}
8282

83-
ExpressionBuilder(Instant start, Instant stop) {
83+
ExpressionBuilder(Instant start, Instant end) {
8484
Instant now = null;
85-
if (start == null || stop == null) {
85+
if (start == null || end == null) {
8686
now = DateUtils.nowWithMillisResolution().toInstant();
8787
}
8888

8989
this.start = start != null ? start : now;
90-
this.stop = stop != null ? stop : now;
90+
this.end = end != null ? end : now;
9191
}
9292

9393
protected Expression expression(ParseTree ctx) {
@@ -282,7 +282,7 @@ public Evaluation visitEvaluation(EvaluationContext ctx) {
282282
if (atCtx.AT_START() != null) {
283283
at = start;
284284
} else if (atCtx.AT_END() != null) {
285-
at = stop;
285+
at = end;
286286
} else {
287287
TimeValue timeValue = visitTimeValue(atCtx.timeValue());
288288
// the value can have a floating point

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import java.time.Instant;
1515

16-
public class PromqlAstBuilder extends LogicalPlanBuilder {
16+
public class PromqlAstBuilder extends PromqlLogicalPlanBuilder {
1717

1818
public static final int MAX_EXPRESSION_DEPTH = 200;
1919

@@ -23,8 +23,8 @@ public PromqlAstBuilder() {
2323
this(null, null);
2424
}
2525

26-
public PromqlAstBuilder(Instant start, Instant stop) {
27-
super(start, stop);
26+
public PromqlAstBuilder(Instant start, Instant end) {
27+
super(start, end);
2828
}
2929

3030
public LogicalPlan plan(ParseTree ctx) {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
import static org.elasticsearch.xpack.esql.parser.ParserUtils.visitList;
4545
import static org.elasticsearch.xpack.esql.plan.logical.promql.selector.LabelMatcher.NAME;
4646

47-
public class LogicalPlanBuilder extends ExpressionBuilder {
47+
public class PromqlLogicalPlanBuilder extends ExpressionBuilder {
4848

49-
LogicalPlanBuilder() {
49+
PromqlLogicalPlanBuilder() {
5050
this(null, null);
5151
}
5252

53-
LogicalPlanBuilder(Instant start, Instant stop) {
54-
super(start, stop);
53+
PromqlLogicalPlanBuilder(Instant start, Instant end) {
54+
super(start, end);
5555
}
5656

5757
protected LogicalPlan plan(ParseTree ctx) {

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plan/logical/promql/PromqlCommand.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,34 +27,34 @@
2727
public class PromqlCommand extends UnaryPlan implements TelemetryAware {
2828

2929
private final LogicalPlan promqlPlan;
30-
private final Expression start, stop, step;
30+
private final Expression start, end, step;
3131

3232
// Instant query constructor - shortcut for a range constructor
3333
public PromqlCommand(Source source, LogicalPlan child, LogicalPlan promqlPlan, Expression time) {
3434
this(source, child, promqlPlan, time, time, Literal.timeDuration(source, Duration.ZERO));
3535
}
3636

3737
// Range query constructor
38-
public PromqlCommand(Source source, LogicalPlan child, LogicalPlan promqlPlan, Expression start, Expression stop, Expression step) {
38+
public PromqlCommand(Source source, LogicalPlan child, LogicalPlan promqlPlan, Expression start, Expression end, Expression step) {
3939
super(source, child);
4040
this.promqlPlan = promqlPlan;
4141
this.start = start;
42-
this.stop = stop;
42+
this.end = end;
4343
this.step = step;
4444
}
4545

4646
@Override
4747
protected NodeInfo<PromqlCommand> info() {
48-
return NodeInfo.create(this, PromqlCommand::new, child(), promqlPlan(), start(), stop(), step());
48+
return NodeInfo.create(this, PromqlCommand::new, child(), promqlPlan(), start(), end(), step());
4949
}
5050

5151
@Override
5252
public PromqlCommand replaceChild(LogicalPlan newChild) {
53-
return new PromqlCommand(source(), newChild, promqlPlan(), start(), stop(), step());
53+
return new PromqlCommand(source(), newChild, promqlPlan(), start(), end(), step());
5454
}
5555

5656
public PromqlCommand withPromqlPlan(LogicalPlan newPromqlPlan) {
57-
return new PromqlCommand(source(), child(), newPromqlPlan, start(), stop(), step());
57+
return new PromqlCommand(source(), child(), newPromqlPlan, start(), end(), step());
5858
}
5959

6060
@Override
@@ -85,8 +85,8 @@ public Expression start() {
8585
return start;
8686
}
8787

88-
public Expression stop() {
89-
return stop;
88+
public Expression end() {
89+
return end;
9090
}
9191

9292
public Expression step() {
@@ -95,7 +95,7 @@ public Expression step() {
9595

9696
@Override
9797
public int hashCode() {
98-
return Objects.hash(child(), start, stop, step, promqlPlan);
98+
return Objects.hash(child(), start, end, step, promqlPlan);
9999
}
100100

101101
@Override
@@ -113,10 +113,10 @@ public boolean equals(Object obj) {
113113
public String nodeString() {
114114
StringBuilder sb = new StringBuilder();
115115
sb.append(nodeName());
116-
if (start == stop) {
116+
if (start == end) {
117117
sb.append("time=").append(start);
118118
} else {
119-
sb.append("start=").append(start).append(", stop=").append(stop).append(", step=").append(step);
119+
sb.append("start=").append(start).append(", end=").append(end).append(", step=").append(step);
120120
}
121121
sb.append(" promql=[<>\n");
122122
sb.append(promqlPlan.toString());

0 commit comments

Comments
 (0)