Skip to content

Commit 42ff295

Browse files
committed
[CALCITE-5223] AdjustProjectForCountAggregateRule throws ArrayIndexOutOfBoundsException
1 parent 8b5c17e commit 42ff295

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

core/src/test/resources/sql/sub-query.iq

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5388,4 +5388,43 @@ and exists(
53885388

53895389
!ok
53905390

5391+
5392+
!use scott
5393+
# [CALCITE-5223] AdjustProjectForCountAggregateRule throws ArrayIndexOutOfBoundsException
5394+
SELECT deptno, ename, job, sal,
5395+
sal / (SELECT SUM(sal) FROM Emp WHERE deptno = e.deptno) AS pct_dept
5396+
FROM Emp AS e
5397+
WHERE job = 'CLERK'
5398+
ORDER BY deptno;
5399+
+--------+--------+-------+---------+---------------------+
5400+
| DEPTNO | ENAME | JOB | SAL | PCT_DEPT |
5401+
+--------+--------+-------+---------+---------------------+
5402+
| 10 | MILLER | CLERK | 1300.00 | 0.1485714285714286 |
5403+
| 20 | SMITH | CLERK | 800.00 | 0.07356321839080460 |
5404+
| 20 | ADAMS | CLERK | 1100.00 | 0.1011494252873563 |
5405+
| 30 | JAMES | CLERK | 950.00 | 0.1010638297872340 |
5406+
+--------+--------+-------+---------+---------------------+
5407+
(4 rows)
5408+
5409+
!ok
5410+
5411+
# [CALCITE-5223] AdjustProjectForCountAggregateRule throws ArrayIndexOutOfBoundsException
5412+
SELECT deptno, ename, job, sal,
5413+
sal / (SELECT SUM(sal) FROM Emp WHERE deptno = e.deptno) AS pct_dept,
5414+
sal / (SELECT SUM(sal) FROM Emp) AS pct_total
5415+
FROM Emp AS e
5416+
WHERE job = 'CLERK'
5417+
ORDER BY deptno;
5418+
+--------+--------+-------+---------+---------------------+---------------------+
5419+
| DEPTNO | ENAME | JOB | SAL | PCT_DEPT | PCT_TOTAL |
5420+
+--------+--------+-------+---------+---------------------+---------------------+
5421+
| 10 | MILLER | CLERK | 1300.00 | 0.1485714285714286 | 0.04478897502153316 |
5422+
| 20 | SMITH | CLERK | 800.00 | 0.07356321839080460 | 0.02756244616709733 |
5423+
| 20 | ADAMS | CLERK | 1100.00 | 0.1011494252873563 | 0.03789836347975883 |
5424+
| 30 | JAMES | CLERK | 950.00 | 0.1010638297872340 | 0.03273040482342808 |
5425+
+--------+--------+-------+---------+---------------------+---------------------+
5426+
(4 rows)
5427+
5428+
!ok
5429+
53915430
# End sub-query.iq

0 commit comments

Comments
 (0)