Skip to content

Commit 1cf8479

Browse files
committed
SQL: [Tests] add tests for literals and GROUP BY
Add unit and integration tests where literals are SELECTed in combination with GROUP BY and possibly aggregate functions. Relates to elastic#41411 and elastic#34583 which have been fixed.
1 parent f4a4e41 commit 1cf8479

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

x-pack/plugin/sql/qa/src/main/resources/agg.sql-spec

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,3 +559,9 @@ aggMultiWithHavingUsingInAndNullHandling
559559
SELECT MIN(salary) min, MAX(salary) max, gender g, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g HAVING max IN(74999, null, 74600) ORDER BY gender;
560560
aggMultiGroupByMultiWithHavingUsingInAndNullHandling
561561
SELECT MIN(salary) min, MAX(salary) max, gender g, languages l, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g, languages HAVING max IN (74500, null, 74600) ORDER BY gender, languages;
562+
563+
// group by with literal
564+
implicitGroupByWithLiteral
565+
SELECT 10, MAX("salary") FROM test_emp;
566+
groupByWithLiteralAndCount
567+
SELECT 20, COUNT(*) from test_emp GROUP BY gender ORDER BY 2;

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryFolderTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,24 @@ public void testGroupKeyTypes_DateTime() {
371371
assertThat(ee.output().get(1).toString(), startsWith("a{r}"));
372372
}
373373

374+
public void testSelectLiteralWithGroupBy() {
375+
PhysicalPlan p = plan("SELECT 1, MAX(int) FROM test");
376+
assertEquals(EsQueryExec.class, p.getClass());
377+
EsQueryExec ee = (EsQueryExec) p;
378+
assertEquals(2, ee.output().size());
379+
assertEquals(Arrays.asList("1", "MAX(int)"), Expressions.names(ee.output()));
380+
assertThat(ee.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
381+
containsString("\"max\":{\"field\":\"int\""));
382+
383+
p = plan("SELECT 1, count(*) FROM test GROUP BY int");
384+
assertEquals(EsQueryExec.class, p.getClass());
385+
ee = (EsQueryExec) p;
386+
assertEquals(2, ee.output().size());
387+
assertEquals(Arrays.asList("1", "count(*)"), Expressions.names(ee.output()));
388+
assertThat(ee.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
389+
containsString("\"terms\":{\"field\":\"int\""));
390+
}
391+
374392
public void testConcatIsNotFoldedForNull() {
375393
PhysicalPlan p = plan("SELECT keyword FROM test WHERE CONCAT(keyword, null) IS NULL");
376394
assertEquals(LocalExec.class, p.getClass());

0 commit comments

Comments
 (0)