Skip to content

Commit 9f414a8

Browse files
authored
SQL: [Tests] Add integ tests for selecting a literal and an aggregate (#42121)
The related issue regarding aggregation queries where some literals are also selected together with aggregate function has been fixed with #49570. Add integration tests to verify the behavior. Relates to: #41411
1 parent d01f5fc commit 9f414a8

File tree

1 file changed

+45
-3
lines changed

1 file changed

+45
-3
lines changed

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ SELECT gender g, MAX(emp_no) m FROM "test_emp" GROUP BY g HAVING MAX(emp_no) > 1
348348
aggMaxWithHavingOnAlias
349349
SELECT gender g, MAX(emp_no) m FROM "test_emp" GROUP BY g HAVING m > 10 ORDER BY g ;
350350
aggMaxWithMultipleHaving
351-
SELECT gender g, MAX(emp_no) m FROM "test_emp" GROUP BY g HAVING m > 10 AND m < 99999 ORDER BY gender;
351+
SELECT gender g, MAX(emp_no) m FROM "test_emp" GROUP BY g HAVING m > 10 AND m < 99999 ORDER BY gender;
352352
aggMaxWithMultipleHavingBetween
353353
SELECT gender g, MAX(emp_no) m FROM "test_emp" GROUP BY g HAVING m BETWEEN 10 AND 99999 ORDER BY g ;
354354
aggMaxWithMultipleHavingWithLimit
@@ -435,7 +435,7 @@ SELECT 1 FROM test_emp HAVING COUNT(*) > 0;
435435
implicitGroupingWithLiteralAliasAndFiltering
436436
SELECT 1 AS l FROM test_emp HAVING COUNT(*) > 0;
437437
implicitGroupingWithLiteralAndFilteringOnAlias
438-
SELECT 1, COUNT(*) AS c FROM test_emp HAVING c > 0;
438+
SELECT 1, COUNT(*) AS c FROM test_emp HAVING c > 0;
439439
implicitGroupingWithLiteralAliasAndFilteringOnAlias
440440
SELECT 1 AS l FROM test_emp HAVING COUNT(*) > 0;
441441
implicitGroupingWithAggs
@@ -497,7 +497,7 @@ SELECT MIN(salary) mi, MAX(salary) ma, MAX(salary) - MIN(salary) AS d FROM test_
497497

498498

499499
//
500-
// Mixture of aggs that get promoted plus filtering on one of them
500+
// Mixture of aggs that get promoted plus filtering on one of them
501501
//
502502
aggMultiWithHaving
503503
SELECT MIN(salary) min, MAX(salary) max, gender g, COUNT(*) c FROM "test_emp" WHERE languages > 0 GROUP BY g HAVING max > 74600 ORDER BY gender;
@@ -565,3 +565,45 @@ implicitGroupByWithLiteral
565565
SELECT 10, MAX("salary") FROM test_emp;
566566
groupByWithLiteralAndCount
567567
SELECT 20, COUNT(*) from test_emp GROUP BY gender ORDER BY 2;
568+
groupByNumberWithLiteral
569+
SELECT emp_no e, 5 FROM "test_emp" GROUP BY emp_no ORDER BY e DESC;
570+
groupByNumberWithWhereWithLiteral
571+
SELECT emp_no e, 5 FROM "test_emp" WHERE emp_no < 10020 GROUP BY e ORDER BY emp_no DESC;
572+
groupByMulScalarWithLiterals
573+
SELECT emp_no * 2 AS e , 5, TRUE FROM test_emp GROUP BY e ORDER BY e;
574+
groupByMulScalarWithWhereWithLiterals
575+
SELECT emp_no * 2 AS e, 5, TRUE FROM test_emp WHERE emp_no < 10020 GROUP BY e ORDER BY e;
576+
aggMaxImplicitWithLiteral
577+
SELECT MAX(salary) AS max, 5 FROM test_emp;
578+
aggMaxImplicitWithCastWithLiteral
579+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM "test_emp";
580+
aggMaxImplicitWithCastWithWhereWithLiteral
581+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM "test_emp" WHERE emp_no > 10000;
582+
aggSumWithCastWithLiteral
583+
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE FROM "test_emp" GROUP BY gender ORDER BY gender;
584+
aggSumWithCastWithAliasWithLiteral
585+
SELECT TRUE, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp" GROUP BY g ORDER BY g DESC;
586+
aggSumWithWhereWithLiteral
587+
SELECT TRUE, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp" WHERE emp_no > 10000 GROUP BY gender ORDER BY gender;
588+
589+
// group by with aliased literal
590+
groupByNumberWithLiteralWithAlias
591+
SELECT emp_no e, 5 department FROM "test_emp" GROUP BY emp_no ORDER BY e DESC;
592+
groupByNumberWithWhereWithLiteralWithAlias
593+
SELECT emp_no e, 5 department FROM "test_emp" WHERE emp_no < 10020 GROUP BY e ORDER BY emp_no DESC;
594+
groupByMulScalarWithLiteralsWithAliases
595+
SELECT emp_no * 2 AS e, 5 department, TRUE as employed FROM test_emp GROUP BY e ORDER BY e;
596+
groupByMulScalarWithWhereWithLiteralsWithAliases
597+
SELECT emp_no * 2 AS e, 5 department, TRUE as employed FROM test_emp WHERE emp_no < 10020 GROUP BY e ORDER BY e;
598+
aggMaxImplicitWithLiteralWithAlias
599+
SELECT MAX(salary) AS max, 5 department FROM test_emp;
600+
aggMaxImplicitWithCastWithLiteralWithAlias
601+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM "test_emp";
602+
aggMaxImplicitWithCastWithWhereWithLiteralWithAlias
603+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM "test_emp" WHERE emp_no > 10000;
604+
aggSumWithCastWithLiteralWithAlias
605+
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE as employed FROM "test_emp" GROUP BY gender ORDER BY gender;
606+
aggSumWithCastWithAliasWithLiteralWithAlias
607+
SELECT TRUE as employed, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp" GROUP BY g ORDER BY g DESC;
608+
aggSumWithWhereWithLiteralWithAlias
609+
SELECT TRUE as employed, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp" WHERE emp_no > 10000 GROUP BY gender ORDER BY gender;

0 commit comments

Comments
 (0)