xiedeyantu commented on code in PR #4670:
URL: https://github.com/apache/calcite/pull/4670#discussion_r2600889159
##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -5505,4 +5505,41 @@ WHERE EXISTS
(2 rows)
!ok
+
+# [CALCITE-7297] The result is incorrect when the GROUP BY key in a subquery
is a RexFieldAccess
+SELECT *,
+ (SELECT COUNT(*)
+ FROM
+ (
+ SELECT empno, ename, job
+ FROM emp
+ WHERE emp.deptno = dept.deptno) AS sub
+ GROUP BY deptno) AS num_dept_groups
+FROM dept;
++--------+------------+----------+-----------------+
Review Comment:
If grouping sets are not supported, I think you can submit another Jira to
describe this issue, focusing first on the group by key scenario.
##########
core/src/test/resources/sql/sub-query.iq:
##########
@@ -5505,4 +5505,54 @@ WHERE EXISTS
(2 rows)
!ok
+
+# [CALCITE-7297] The result is incorrect when the GROUP BY key in a subquery
is a RexFieldAccess
+SELECT *,
+ (SELECT COUNT(*)
+ FROM
+ (
+ SELECT empno, ename, job
+ FROM emp
+ WHERE emp.deptno = dept.deptno) AS sub
+ GROUP BY deptno) AS num_dept_groups
+FROM dept;
++--------+------------+----------+-----------------+
+| DEPTNO | DNAME | LOC | NUM_DEPT_GROUPS |
++--------+------------+----------+-----------------+
+| 10 | ACCOUNTING | NEW YORK | 3 |
+| 20 | RESEARCH | DALLAS | 5 |
+| 30 | SALES | CHICAGO | 6 |
+| 40 | OPERATIONS | BOSTON | |
++--------+------------+----------+-----------------+
+(4 rows)
+
+!ok
+
+# [CALCITE-7297] The result is incorrect when the GROUP BY key in a subquery
is a RexFieldAccess
+SELECT *,
+ (SELECT COUNT(*)
+ FROM
+ (
+ SELECT empno, ename, job, comm
+ FROM emp
+ WHERE emp.deptno = dept.deptno) AS sub
+ GROUP BY sub.comm) AS num_dept_groups
+FROM dept;
+more than one value in agg SINGLE_VALUE
+!error
Review Comment:
Could you change to this?
```
SELECT *
, (
SELECT COUNT(*)
FROM (
SELECT empno, ename, job, comm
FROM emp
WHERE emp.deptno = dept.deptno
LIMIT 1
) sub
GROUP BY sub.comm
) AS num_dept_groups
FROM dept;
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]