Skip to content

Commit 3e7f939

Browse files
committed
SQL: [Tests] Add more tests for aggs and literals (#52086)
Add some more tests where more than one literal is selected, unaliased and aliased. Follows: #42121 (cherry picked from commit 405271d)
1 parent c4c0db6 commit 3e7f939

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,12 @@ SELECT MIN(salary) min, MAX(salary) max, gender g, languages l, COUNT(*) c FROM
563563
// group by with literal
564564
implicitGroupByWithLiteral
565565
SELECT 10, MAX("salary") FROM test_emp;
566-
groupByWithLiteralAndCount
566+
implicitGroupByWithLiterals
567+
SELECT 10, 'foo', MAX("salary"), 20, 'bar' FROM test_emp;
568+
groupByWithLiteral
567569
SELECT 20, COUNT(*) from test_emp GROUP BY gender ORDER BY 2;
570+
groupByWithLiterals
571+
SELECT 10, 'foo', COUNT(*), '20', 'bar' from test_emp GROUP BY gender ORDER BY 3;
568572
groupByNumberWithLiteral
569573
SELECT emp_no e, 5 FROM "test_emp" GROUP BY emp_no ORDER BY e DESC;
570574
groupByNumberWithWhereWithLiteral
@@ -573,20 +577,24 @@ groupByMulScalarWithLiterals
573577
SELECT emp_no * 2 AS e , 5, TRUE FROM test_emp GROUP BY e ORDER BY e;
574578
groupByMulScalarWithWhereWithLiterals
575579
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;
578580
aggMaxImplicitWithCastWithLiteral
579-
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM "test_emp";
581+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM test_emp;
580582
aggMaxImplicitWithCastWithWhereWithLiteral
581-
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM "test_emp" WHERE emp_no > 10000;
583+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 FROM test_emp WHERE emp_no > 10000;
582584
aggSumWithCastWithLiteral
583-
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE FROM "test_emp" GROUP BY gender ORDER BY gender;
585+
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE FROM test_emp GROUP BY gender ORDER BY gender;
584586
aggSumWithCastWithAliasWithLiteral
585-
SELECT TRUE, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM "test_emp" GROUP BY g ORDER BY g DESC;
587+
SELECT TRUE, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM test_emp GROUP BY g ORDER BY g DESC;
586588
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;
589+
SELECT TRUE, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM test_emp WHERE emp_no > 10000 GROUP BY gender ORDER BY gender;
588590

589591
// group by with aliased literal
592+
implicitGroupByWithLiteralWithAlias
593+
SELECT 10 AS a, MAX("salary") AS max FROM test_emp;
594+
implicitGroupByWithLiteralsWithAliases
595+
SELECT 10 AS a, 'foo', MAX("salary") AS max, 20, 'bar' AS d FROM test_emp;
596+
groupByWithLiteralsWithAliases
597+
SELECT 10 AS a, 'foo', COUNT(*) AS cnt, '20', 'bar' AS d from test_emp GROUP BY gender ORDER BY 3;
590598
groupByNumberWithLiteralWithAlias
591599
SELECT emp_no e, 5 department FROM "test_emp" GROUP BY emp_no ORDER BY e DESC;
592600
groupByNumberWithWhereWithLiteralWithAlias
@@ -595,15 +603,13 @@ groupByMulScalarWithLiteralsWithAliases
595603
SELECT emp_no * 2 AS e, 5 department, TRUE as employed FROM test_emp GROUP BY e ORDER BY e;
596604
groupByMulScalarWithWhereWithLiteralsWithAliases
597605
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;
600606
aggMaxImplicitWithCastWithLiteralWithAlias
601-
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM "test_emp";
607+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM test_emp;
602608
aggMaxImplicitWithCastWithWhereWithLiteralWithAlias
603-
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM "test_emp" WHERE emp_no > 10000;
609+
SELECT CAST(MAX(emp_no) AS SMALLINT) c, 5 department FROM test_emp WHERE emp_no > 10000;
604610
aggSumWithCastWithLiteralWithAlias
605-
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE as employed FROM "test_emp" GROUP BY gender ORDER BY gender;
611+
SELECT gender g, CAST(SUM(emp_no) AS BIGINT) s, TRUE as employed FROM test_emp GROUP BY gender ORDER BY gender;
606612
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;
613+
SELECT TRUE as employed, gender g, CAST(SUM(emp_no) AS BIGINT) s FROM test_emp GROUP BY g ORDER BY g DESC;
608614
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;
615+
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)