SQL: [Tests] add tests for literals and GROUP BY (#51878)

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.

(cherry picked from commit b97f1ca12675d6ea4772c60578922fe1cc2409ee)
This commit is contained in:
Marios Trivyzas 2020-02-05 12:32:40 +01:00
parent ababd730f6
commit 64f9a2089b
2 changed files with 24 additions and 0 deletions

View File

@ -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;

View File

@ -371,6 +371,24 @@ public class QueryFolderTests extends ESTestCase {
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());