Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

package org.elasticsearch.xpack.esql.optimizer;

import org.elasticsearch.xpack.esql.VerificationException;
import org.elasticsearch.xpack.esql.common.Failures;
import org.elasticsearch.xpack.esql.core.type.DataType;
import org.elasticsearch.xpack.esql.optimizer.rules.PruneInlineJoinOnEmptyRightSide;
import org.elasticsearch.xpack.esql.optimizer.rules.logical.BooleanFunctionEqualsElimination;
Expand Down Expand Up @@ -72,6 +74,7 @@
import org.elasticsearch.xpack.esql.optimizer.rules.logical.local.PruneLeftJoinOnNullMatchingField;
import org.elasticsearch.xpack.esql.optimizer.rules.logical.promql.TranslatePromqlToTimeSeriesAggregate;
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan;
import org.elasticsearch.xpack.esql.plan.logical.promql.PromqlCommand;
import org.elasticsearch.xpack.esql.rule.ParameterizedRuleExecutor;
import org.elasticsearch.xpack.esql.rule.RuleExecutor;

Expand Down Expand Up @@ -118,10 +121,11 @@ 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());
// TODO re-enable verification for PromQL once we make sure the output columns don't change
if (failures.hasFailures() && verified.anyMatch(PromqlCommand.class::isInstance) == false) {
throw new VerificationException(failures);
}
optimized.setOptimized();
return optimized;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.esql.analysis.Analyzer;
import org.elasticsearch.xpack.esql.analysis.AnalyzerTestUtils;
import org.junit.Ignore;

import java.util.List;

Expand Down Expand Up @@ -60,10 +59,11 @@ public void testPromqlSubquery() {
);
}

@Ignore
@AwaitsFix(
bugUrl = "Doesn't parse: line 1:27: Invalid query '1+1'[ArithmeticBinaryContext] given; "
+ "expected LogicalPlan but found VectorBinaryArithmetic"
)
public void testPromqlArithmetricOperators() {
// TODO doesn't parse
// line 1:27: Invalid query '1+1'[ArithmeticBinaryContext] given; expected LogicalPlan but found VectorBinaryArithmetic
assertThat(
error("TS test | PROMQL step 5m (1+1)", tsdb),
equalTo("1:27: arithmetic operators are not supported at this time [foo]")
Expand All @@ -82,11 +82,11 @@ public void testPromqlArithmetricOperators() {
);
}

@Ignore
@AwaitsFix(
bugUrl = "Doesn't parse: line 1:27: Invalid query 'method_code_http_errors_rate5m{code=\"500\"}'"
+ "[ValueExpressionContext] given; expected Expression but found InstantSelector"
)
public void testPromqlVectorMatching() {
// TODO doesn't parse
// line 1:27: Invalid query 'method_code_http_errors_rate5m{code="500"}'[ValueExpressionContext] given; expected Expression but
// found InstantSelector
assertThat(
error(
"TS test | PROMQL step 5m (method_code_http_errors_rate5m{code=\"500\"} / ignoring(code) method_http_requests_rate5m)",
Expand Down Expand Up @@ -115,10 +115,11 @@ public void testPromqlModifier() {
);*/
}

@Ignore
@AwaitsFix(
bugUrl = "Doesn't parse: line 1:27: Invalid query 'foo and bar'[LogicalBinaryContext] given; "
+ "expected Expression but found InstantSelector"
)
public void testLogicalSetBinaryOperators() {
// TODO doesn't parse
// line 1:27: Invalid query 'foo'[ValueExpressionContext] given; expected Expression but found InstantSelector
assertThat(error("TS test | PROMQL step 5m (foo and bar)", tsdb), equalTo(""));
assertThat(error("TS test | PROMQL step 5m (foo or bar)", tsdb), equalTo(""));
assertThat(error("TS test | PROMQL step 5m (foo unless bar)", tsdb), equalTo(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public void testRangeSelector() {
logger.info(plan);
}

@AwaitsFix(bugUrl = "Invalid call to dataType on an unresolved object ?RATE_$1")
public void testRate() {
// TS metrics-hostmetricsreceiver.otel-default
// | WHERE @timestamp >= \"{{from | minus .benchmark.duration}}\" AND @timestamp <= \"{{from}}\"
Expand Down Expand Up @@ -243,6 +244,7 @@ public void testLabelSelectorRegex() {
assertThat(filter.condition().anyMatch(RegexMatch.class::isInstance), equalTo(true));
}

@AwaitsFix(bugUrl = "This should never be called before the attribute is resolved")
public void testFsUsageTop5() {
// TS metrics-hostmetricsreceiver.otel-default | WHERE @timestamp >= \"{{from | minus .benchmark.duration}}\" AND @timestamp <=
// \"{{from}}\"
Expand All @@ -263,6 +265,7 @@ sum by (host.name, mountpoint) (last_over_time(system.filesystem.usage{state=~"u
logger.info(plan);
}

@AwaitsFix(bugUrl = "only aggregations across timeseries are supported at this time (found [foo or bar])")
public void testGrammar() {
// TS metrics-hostmetricsreceiver.otel-default | WHERE @timestamp >= \"{{from | minus .benchmark.duration}}\" AND @timestamp <=
// \"{{from}}\"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public void testValidQueries() throws Exception {
}
}

@AwaitsFix(bugUrl = "query doesn't fail to parse while it should: `foo offset 9.5e10`")
public void testUnsupportedQueries() throws Exception {
List<Tuple<String, Integer>> lines = readQueries("/promql/grammar/queries-invalid.promql");
for (Tuple<String, Integer> line : lines) {
Expand Down