Skip to content

Commit fefa0f0

Browse files
authored
ESQL: add tests on use of grouping functions in agg filters (#117184)
Add tests on use of grouping functions in agg filters: check that reusing the BUCKET expression from grouping is allowed, but no other variation. Related: #115521
1 parent c190c57 commit fefa0f0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

x-pack/plugin/esql/qa/testFixtures/src/main/resources/bucket.csv-spec

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -760,3 +760,19 @@ c:long |b:date
760760
3 |2025-10-01T00:00:00.000Z
761761
4 |2023-11-01T00:00:00.000Z
762762
;
763+
764+
bucketWithFilteredCountRefingBucket
765+
required_capability: implicit_casting_string_literal_to_temporal_amount
766+
767+
FROM employees
768+
| STATS c = COUNT(*) WHERE b > "1953-01-01T00:00:00.000Z" AND emp_no > 10020 BY b = BUCKET(birth_date, 1 year)
769+
| SORT c, b
770+
| LIMIT 4
771+
;
772+
773+
c:long |b:date
774+
0 |1952-01-01T00:00:00.000Z
775+
0 |1953-01-01T00:00:00.000Z
776+
0 |null
777+
1 |1965-01-01T00:00:00.000Z
778+
;

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/analysis/VerifierTests.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,11 @@ public void testAggFilterOnBucketingOrAggFunctions() {
404404
query("from test | stats max(languages) WHERE bucket(salary, 10) > 1 by bucket(salary, 10)");
405405

406406
// but fails if it's different
407+
assertEquals(
408+
"1:32: can only use grouping function [bucket(a, 3)] part of the BY clause",
409+
error("row a = 1 | stats sum(a) where bucket(a, 3) > -1 by bucket(a,2)")
410+
);
411+
407412
assertEquals(
408413
"1:40: can only use grouping function [bucket(salary, 10)] part of the BY clause",
409414
error("from test | stats max(languages) WHERE bucket(salary, 10) > 1 by emp_no")

0 commit comments

Comments
 (0)