Skip to content

Commit 18d0487

Browse files
committed
more verification tests
1 parent 34832df commit 18d0487

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/approximate/Approximate.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ private boolean verifyPlan() throws VerificationException {
251251
// Verify that all commands are supported.
252252
logicalPlan.forEachUp(plan -> {
253253
if (SUPPORTED_COMMANDS.contains(plan.getClass()) == false) {
254+
// TODO: better way of obtaining the command name
254255
throw new VerificationException(
255256
List.of(Failure.fail(plan, "query with [" + plan.nodeName().toUpperCase(Locale.ROOT) + "] cannot be approximated"))
256257
);
@@ -267,6 +268,7 @@ private boolean verifyPlan() throws VerificationException {
267268
plan.transformExpressionsOnly(AggregateFunction.class, aggFn -> {
268269
if (SUPPORTED_SINGLE_VALUED_AGGS.contains(aggFn.getClass()) == false
269270
&& SUPPORTED_MULTIVALUED_AGGS.contains(aggFn.getClass()) == false) {
271+
// TODO: better way of obtaining the agg name
270272
throw new VerificationException(
271273
List.of(
272274
Failure.fail(

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/approximate/ApproximateTests.java

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,23 @@ public void testVerify_validQuery() throws Exception {
116116
createApproximate("ROW i=[1,2,3] | EVAL x=TO_STRING(i) | DISSECT x \"%{x}\" | STATS i=10*POW(PERCENTILE(i, 0.5), 2) | LIMIT 10");
117117
}
118118

119-
public void testVerify_noStats() {
120-
assertError("FROM test | EVAL x = 1 | SORT emp_no", equalTo("line 1:1: query without [STATS] cannot be approximated"));
119+
public void testVerify_exactlyOneStats() {
120+
assertError(
121+
"FROM test | EVAL x = 1 | SORT emp_no | LIMIT 100 | MV_EXPAND x",
122+
equalTo("line 1:1: query without [STATS] cannot be approximated")
123+
);
124+
assertError(
125+
"FROM test | STATS COUNT() BY emp_no | STATS COUNT()",
126+
equalTo("line 1:39: query with multiple [STATS] cannot be approximated")
127+
);
121128
}
122129

123-
public void testVerify_incompatibleCommand() {
130+
public void testVerify_incompatibleSourceCommand() {
131+
assertError("SHOW INFO | STATS COUNT()", equalTo("line 1:1: query with [SHOWINFO] cannot be approximated"));
132+
assertError("TS test | STATS COUNT(emp_no)", equalTo("line 1:11: query with [TIMESERIESAGGREGATE] cannot be approximated"));
133+
}
134+
135+
public void testVerify_incompatibleProcessingCommand() {
124136
assertError(
125137
"FROM test | FORK (EVAL x=1) (EVAL y=1) | STATS COUNT()",
126138
equalTo("line 1:13: query with [FORK] cannot be approximated")
@@ -138,19 +150,22 @@ public void testVerify_incompatibleCommand() {
138150
equalTo("line 1:29: query with [INLINESTATS] cannot be approximated")
139151
);
140152
assertError(
141-
"FROM test | LOOKUP JOIN test_lookup ON emp_no | STATS COUNT()",
153+
"FROM test | LOOKUP JOIN test_lookup ON emp_no | FORK (EVAL x=1) (EVAL y=1) | STATS COUNT()",
142154
equalTo("line 1:13: query with [LOOKUPJOIN] cannot be approximated")
143155
);
144156
assertError(
145-
"FROM test | STATS emp_no=COUNT() | LOOKUP JOIN test_lookup ON emp_no",
157+
"FROM test | STATS emp_no=COUNT() | LOOKUP JOIN test_lookup ON emp_no | FORK (EVAL x=1) (EVAL y=1)",
146158
equalTo("line 1:36: query with [LOOKUPJOIN] cannot be approximated")
147159
);
148160
}
149161

150162
public void testVerify_incompatibleAggregation() {
151-
assertError("FROM test | STATS MIN(emp_no)", equalTo("line 1:19: aggregation function [MIN] cannot be approximated"));
152163
assertError(
153-
"FROM test | STATS SUM(emp_no), VALUES(emp_no), COUNT()",
164+
"FROM test | SORT emp_no STATS MIN(emp_no) | LIMIT 100",
165+
equalTo("line 1:19: aggregation function [MIN] cannot be approximated")
166+
);
167+
assertError(
168+
"FROM test | STATS SUM(emp_no), VALUES(emp_no), TOP(emp_no, 2, \"ASC\"), COUNT()",
154169
equalTo("line 1:32: aggregation function [VALUES] cannot be approximated")
155170
);
156171
assertError(

0 commit comments

Comments
 (0)