Skip to content

Commit de90f2b

Browse files
committed
Merge remote-tracking branch 'felixbarny/promql-parameter-parsing' into promql-parameter-parsing
2 parents 10a7adf + abef75e commit de90f2b

File tree

10 files changed

+40
-64
lines changed

10 files changed

+40
-64
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/promql/predicate/operator/VectorBinaryOperator.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
import org.elasticsearch.xpack.esql.core.expression.function.Function;
1515
import org.elasticsearch.xpack.esql.core.tree.Source;
1616
import org.elasticsearch.xpack.esql.core.type.DataType;
17-
import org.elasticsearch.xpack.esql.evaluator.mapper.EvaluatorMapper;
18-
import org.elasticsearch.xpack.esql.expression.function.scalar.EsqlScalarFunction;
1917
import org.elasticsearch.xpack.esql.plan.logical.BinaryPlan;
2018
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
2119
import org.elasticsearch.xpack.esql.plan.logical.promql.selector.LabelMatcher;
@@ -163,9 +161,7 @@ public boolean equals(Object o) {
163161
if (o == null || getClass() != o.getClass()) return false;
164162
if (super.equals(o)) {
165163
VectorBinaryOperator that = (VectorBinaryOperator) o;
166-
return dropMetricName == that.dropMetricName
167-
&& Objects.equals(match, that.match)
168-
&& Objects.equals(binaryOp, that.binaryOp);
164+
return dropMetricName == that.dropMetricName && Objects.equals(match, that.match) && Objects.equals(binaryOp, that.binaryOp);
169165
}
170166
return false;
171167
}

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/promql/predicate/operator/comparison/VectorBinaryComparison.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ public ScalarFunctionFactory asFunction() {
4747
private final ComparisonOp op;
4848
private final boolean boolMode;
4949

50-
public VectorBinaryComparison(Source source, LogicalPlan left, LogicalPlan right, VectorMatch match, boolean boolMode, ComparisonOp op) {
50+
public VectorBinaryComparison(
51+
Source source,
52+
LogicalPlan left,
53+
LogicalPlan right,
54+
VectorMatch match,
55+
boolean boolMode,
56+
ComparisonOp op
57+
) {
5158
super(source, left, right, match, boolMode == false, op);
5259
this.op = op;
5360
this.boolMode = boolMode;

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,7 @@ public Duration visitDuration(DurationContext ctx) {
173173
}
174174

175175
// Non-literal LogicalPlan
176-
throw new ParsingException(
177-
source(ctx),
178-
"Duration must be a constant expression"
179-
);
176+
throw new ParsingException(source(ctx), "Duration must be a constant expression");
180177
}
181178
case Expression e -> {
182179
// Fallback for Expression (shouldn't happen with new logic)

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ private static Duration arithmetics(Source source, Duration left, Duration right
6464
Duration result = switch (op) {
6565
case ADD -> left.plus(right);
6666
case SUB -> left.minus(right);
67-
default -> throw new ParsingException(
68-
source,
69-
"Operation [{}] not supported between two durations",
70-
op
71-
);
67+
default -> throw new ParsingException(source, "Operation [{}] not supported between two durations", op);
7268
};
7369

7470
return result;

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ public Duration visitSubqueryResolution(PromqlBaseParser.SubqueryResolutionConte
548548
return duration;
549549
}
550550

551-
throw new ParsingException(source(ctx), "Expected duration result, got [{}]",
552-
result.getClass().getSimpleName());
551+
throw new ParsingException(source(ctx), "Expected duration result, got [{}]", result.getClass().getSimpleName());
553552
}
554553

555554
// Just COLON with no resolution - use default

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.elasticsearch.xpack.esql.plan.logical.promql.PlaceholderRelation;
1919

2020
import java.io.IOException;
21-
import java.sql.Time;
2221
import java.util.List;
2322
import java.util.Objects;
2423

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/promql/PromqlLogicalPlanOptimizerTests.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
import org.elasticsearch.xpack.esql.action.EsqlCapabilities;
1414
import org.elasticsearch.xpack.esql.analysis.Analyzer;
1515
import org.elasticsearch.xpack.esql.analysis.AnalyzerContext;
16-
import org.elasticsearch.xpack.esql.core.tree.Source;
1716
import org.elasticsearch.xpack.esql.core.expression.predicate.regex.RegexMatch;
17+
import org.elasticsearch.xpack.esql.core.tree.Source;
1818
import org.elasticsearch.xpack.esql.expression.function.EsqlFunctionRegistry;
1919
import org.elasticsearch.xpack.esql.expression.function.scalar.string.StartsWith;
2020
import org.elasticsearch.xpack.esql.expression.predicate.operator.comparison.In;
@@ -280,26 +280,26 @@ public void testGrammar() {
280280
System.out.println(plan);
281281
}
282282

283-
// public void testPromqlArithmetricOperators() {
284-
// // TODO doesn't parse
285-
// // line 1:27: Invalid query '1+1'[ArithmeticBinaryContext] given; expected LogicalPlan but found VectorBinaryArithmetic
286-
// assertThat(
287-
// error("TS test | PROMQL step 5m (1+1)", tsdb),
288-
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
289-
// );
290-
// assertThat(
291-
// error("TS test | PROMQL step 5m ( foo and bar )", tsdb),
292-
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
293-
// );
294-
// assertThat(
295-
// error("TS test | PROMQL step 5m (1+foo)", tsdb),
296-
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
297-
// );
298-
// assertThat(
299-
// error("TS test | PROMQL step 5m (foo+bar)", tsdb),
300-
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
301-
// );
302-
// }
283+
// public void testPromqlArithmetricOperators() {
284+
// // TODO doesn't parse
285+
// // line 1:27: Invalid query '1+1'[ArithmeticBinaryContext] given; expected LogicalPlan but found VectorBinaryArithmetic
286+
// assertThat(
287+
// error("TS test | PROMQL step 5m (1+1)", tsdb),
288+
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
289+
// );
290+
// assertThat(
291+
// error("TS test | PROMQL step 5m ( foo and bar )", tsdb),
292+
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
293+
// );
294+
// assertThat(
295+
// error("TS test | PROMQL step 5m (1+foo)", tsdb),
296+
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
297+
// );
298+
// assertThat(
299+
// error("TS test | PROMQL step 5m (foo+bar)", tsdb),
300+
// equalTo("1:1: arithmetic operators are not supported at this time [foo]")
301+
// );
302+
// }
303303

304304
protected LogicalPlan planPromql(String query) {
305305
var analyzed = tsAnalyzer.analyze(parser.createStatement(query));

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/promql/PromqlAstTests.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@
77

88
package org.elasticsearch.xpack.esql.parser.promql;
99

10-
import org.elasticsearch.common.logging.Loggers;
1110
import org.elasticsearch.core.Tuple;
1211
import org.elasticsearch.logging.LogManager;
1312
import org.elasticsearch.logging.Logger;
1413
import org.elasticsearch.test.ESTestCase;
15-
import org.elasticsearch.test.junit.annotations.TestLogging;
1614
import org.elasticsearch.xpack.esql.EsqlTestUtils;
1715
import org.elasticsearch.xpack.esql.core.QlClientException;
1816
import org.elasticsearch.xpack.esql.parser.ParsingException;
@@ -32,7 +30,7 @@
3230
* Test for checking the overall grammar by throwing a number of valid queries at the parser to see whether any exception is raised.
3331
* In time, the queries themselves get to be checked against the actual execution model and eventually against the expected results.
3432
*/
35-
//@TestLogging(reason = "debug", value = "org.elasticsearch.xpack.esql.parser.promql:TRACE")
33+
// @TestLogging(reason = "debug", value = "org.elasticsearch.xpack.esql.parser.promql:TRACE")
3634
public class PromqlAstTests extends ESTestCase {
3735

3836
private static final Logger log = LogManager.getLogger(PromqlAstTests.class);

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/promql/PromqlParamsTests.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,7 @@ public void testZeroStep() {
7171
}
7272

7373
public void testNegativeStep() {
74-
ParsingException e = assertThrows(
75-
ParsingException.class,
76-
() -> parse("TS test | PROMQL step `-1` (avg(foo))")
77-
);
74+
ParsingException e = assertThrows(ParsingException.class, () -> parse("TS test | PROMQL step `-1` (avg(foo))"));
7875
assertThat(
7976
e.getMessage(),
8077
containsString("invalid parameter \"step\": zero or negative query resolution step widths are not accepted")
@@ -113,10 +110,7 @@ public void testUnknownParameter() {
113110
}
114111

115112
public void testUnknownParameterNoSuggestion() {
116-
ParsingException e = assertThrows(
117-
ParsingException.class,
118-
() -> parse("TS test | PROMQL foo 1 (avg(foo))")
119-
);
113+
ParsingException e = assertThrows(ParsingException.class, () -> parse("TS test | PROMQL foo 1 (avg(foo))"));
120114
assertThat(e.getMessage(), containsString("Unknown parameter [foo]"));
121115
}
122116

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/promql/PromqlParserUtilsTests.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,14 @@ public void testTimeValueCombined() throws Exception {
5353
assertEquals(ofDays(365).plus(ofSeconds(6)), parseTimeValue("1y6s"));
5454
assertEquals(ofDays(365).plus(ofMillis(7)), parseTimeValue("1y7ms"));
5555

56-
assertEquals(
57-
ofDays(365).plus(ofDays(14)).plus(ofDays(3)),
58-
parseTimeValue("1y2w3d")
59-
);
56+
assertEquals(ofDays(365).plus(ofDays(14)).plus(ofDays(3)), parseTimeValue("1y2w3d"));
6057

61-
assertEquals(
62-
ofDays(365).plus(ofDays(3)).plus(ofHours(4)),
63-
parseTimeValue("1y3d4h")
64-
);
58+
assertEquals(ofDays(365).plus(ofDays(3)).plus(ofHours(4)), parseTimeValue("1y3d4h"));
6559

66-
assertEquals(
67-
ofDays(365).plus(ofMinutes(5)).plus(ofSeconds(6)),
68-
parseTimeValue("1y5m6s")
69-
);
60+
assertEquals(ofDays(365).plus(ofMinutes(5)).plus(ofSeconds(6)), parseTimeValue("1y5m6s"));
7061

7162
assertEquals(
72-
ofDays(365).plus(ofDays(7)).plus(ofDays(1)).plus(ofHours(1))
73-
.plus(ofMinutes(1)).plus(ofSeconds(1)).plus(ofMillis(1)),
63+
ofDays(365).plus(ofDays(7)).plus(ofDays(1)).plus(ofHours(1)).plus(ofMinutes(1)).plus(ofSeconds(1)).plus(ofMillis(1)),
7464
parseTimeValue("1y1w1d1h1m1s1ms")
7565
);
7666

0 commit comments

Comments
 (0)