yanlin-Lynn commented on a change in pull request #1710: [CALCITE-2672] 
Qualifying the common column should not be allowed in Oracle dialect
URL: https://github.com/apache/calcite/pull/1710#discussion_r362194242
 
 

 ##########
 File path: 
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java
 ##########
 @@ -527,24 +527,48 @@ private static SqlNode expandExprFromJoin(SqlJoin join, 
SqlIdentifier identifier
   }
 
   private static SqlNode expandCommonColumn(SqlSelect sqlSelect,
-      SqlNode selectItem, SelectScope scope) {
+      SqlNode selectItem, SelectScope scope, SqlValidator validator) {
     if (!(selectItem instanceof SqlIdentifier)) {
       return selectItem;
     }
 
-    final SqlIdentifier identifier = (SqlIdentifier) selectItem;
-    if (!identifier.isSimple()) {
+    final SqlNode from = sqlSelect.getFrom();
+    if (from == null || !(from instanceof SqlJoin)) {
       return selectItem;
     }
 
-    final SqlNode from = sqlSelect.getFrom();
-    if (from == null || !(from instanceof SqlJoin)) {
+    final SqlIdentifier identifier = (SqlIdentifier) selectItem;
+    final SqlConformance conformance = validator.getConformance();
+    if (!identifier.isSimple()) {
+      if (!conformance.allowQualifyingCommonColumn()) {
+        validateQualifiedCommonColumn((SqlJoin) from, identifier, scope, 
validator);
+      }
       return selectItem;
     }
 
     return expandExprFromJoin((SqlJoin) from, identifier, scope);
   }
 
+  private static void validateQualifiedCommonColumn(SqlJoin join,
+      SqlIdentifier identifier, SelectScope scope, SqlValidator validator) {
+    if (!(join.isNatural() || join.getConditionType() == 
JoinConditionType.USING)) {
+      return;
+    }
+    for (ScopeChild child : scope.children) {
+      if (child.name.equals(identifier.getComponent(0).toString())) {
 
 Review comment:
   if the column is not a common column ,like `select emp.ename from emp join 
dept using(deptno)`, it should not fail.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to