chunweilei commented on a change in pull request #2408:
URL: https://github.com/apache/calcite/pull/2408#discussion_r621751877
##########
File path: core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
##########
@@ -371,7 +372,8 @@ public final Sql sql(String sql) {
}
@Test void testAliasInHaving() {
- sql("select count(empno) as e from emp having e > 1")
+ sql("select ename, count(empno) as e, count(deptno) as d from emp"
+ + " group by ename having e > 1 and count(deptno) > 2")
Review comment:
We'd better add new tests.
##########
File path:
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
##########
@@ -6669,9 +6729,95 @@ private SqlNode nthSelectItem(int ordinal, final
SqlParserPos pos) {
break;
}
}
-
return super.visit(literal);
}
+
+ @Override
+ protected SqlNode visitScoped(SqlCall call) {
+ checkExpandedAsAlias(call);
+ return super.visitScoped(call);
+ }
+
+ void recordExpandingTopNodes(SqlNode root) {
+ List<SqlNode> operands = ((SqlCall) root).getOperandList();
+ for (int i = 0; i < operands.size(); i++) {
+ SqlNode operand = operands.get(i);
+ if (operand.getKind() == SqlKind.ROW) {
+ recordExpandingTopNodes(operand);
+ }
+ if (operand instanceof SqlCall) {
+ expandingTopNodes.put(operand, Boolean.FALSE);
+ } else {
+ expandingTopNodes.put(operand, Boolean.TRUE);
+ }
+ }
+ }
+
+ /*
+ * check if top level node should be expanded as alias.
+ */
+ void checkExpandedAsAlias(SqlNode sqlNode) {
Review comment:
check -> Checks?
##########
File path:
core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
##########
@@ -86,16 +86,19 @@ LogicalAggregate(group=[{0}])
<![CDATA[select empno as d from emp group by d]]>
</Resource>
</TestCase>
- <TestCase name="testGroupByAliasEqualToColumnName">
+ <TestCase name="testGroupByAliasEqualToMultipleColumnName">
<Resource name="plan">
<![CDATA[
LogicalAggregate(group=[{0, 1}])
- LogicalProject(EMPNO=[$0], DEPTNO=[$1])
- LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalProject(EMPNO=[$0], DEPTNO=[$7])
+ LogicalJoin(condition=[true], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalTableScan(table=[[CATALOG, SALES, DEPT]])
]]>
</Resource>
<Resource name="sql">
- <![CDATA[select empno, ename as deptno from emp group by empno,
deptno]]>
+ <![CDATA[select empno, case when emp.deptno is null then
dept.deptno else emp.deptno
+end as deptno from emp, dept group by empno, deptno]]>
</Resource>
Review comment:
Could you add new test cases instead of changing the current one?
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]