Skip to content

Commit

Permalink
SQL: [Tests] add tests for literals and GROUP BY (#51878)
Browse files Browse the repository at this point in the history
Add unit and integration tests where literals are SELECTed
in combination with GROUP BY and possibly aggregate functions.

Relates to #41411 and #34583
which have been fixed.
  • Loading branch information
matriv authored Feb 5, 2020
1 parent d011c7a commit b97f1ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/agg.sql-spec
Original file line number Diff line number Diff line change
Expand Up @@ -559,3 +559,9 @@ aggMultiWithHavingUsingInAndNullHandling
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;
aggMultiGroupByMultiWithHavingUsingInAndNullHandling
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;

// group by with literal
implicitGroupByWithLiteral
SELECT 10, MAX("salary") FROM test_emp;
groupByWithLiteralAndCount
SELECT 20, COUNT(*) from test_emp GROUP BY gender ORDER BY 2;
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,24 @@ public void testGroupKeyTypes_DateTime() {
assertThat(ee.output().get(1).toString(), startsWith("a{r}"));
}

public void testSelectLiteralWithGroupBy() {
PhysicalPlan p = plan("SELECT 1, MAX(int) FROM test");
assertEquals(EsQueryExec.class, p.getClass());
EsQueryExec ee = (EsQueryExec) p;
assertEquals(2, ee.output().size());
assertEquals(Arrays.asList("1", "MAX(int)"), Expressions.names(ee.output()));
assertThat(ee.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
containsString("\"max\":{\"field\":\"int\""));

p = plan("SELECT 1, count(*) FROM test GROUP BY int");
assertEquals(EsQueryExec.class, p.getClass());
ee = (EsQueryExec) p;
assertEquals(2, ee.output().size());
assertEquals(Arrays.asList("1", "count(*)"), Expressions.names(ee.output()));
assertThat(ee.queryContainer().aggs().asAggBuilder().toString().replaceAll("\\s+", ""),
containsString("\"terms\":{\"field\":\"int\""));
}

public void testConcatIsNotFoldedForNull() {
PhysicalPlan p = plan("SELECT keyword FROM test WHERE CONCAT(keyword, null) IS NULL");
assertEquals(LocalExec.class, p.getClass());
Expand Down

0 comments on commit b97f1ca

Please sign in to comment.