caicancai commented on code in PR #4289:
URL: https://github.com/apache/calcite/pull/4289#discussion_r2030184519


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -7393,20 +7393,65 @@ private SqlNode nthSelectItem(int ordinal, final 
SqlParserPos pos) {
    */
   static class SelectExpander extends Expander {
     final SqlSelect select;
+    @Nullable SqlNode root = null;
 
     SelectExpander(SqlValidatorImpl validator, SelectScope scope,
         SqlSelect select) {
       super(validator, scope);
       this.select = select;
     }
 
+    @Override public SqlNode go(SqlNode root) {
+      this.root = root;
+      return super.go(root);
+    }
+
     @Override public @Nullable SqlNode visit(SqlIdentifier id) {
       final SqlNode node =
           expandCommonColumn(select, id, (SelectScope) getScope(), validator);
       if (node != id) {
         return node;
       } else {
-        return super.visit(id);
+        try {
+          return super.visit(id);
+        } catch (Exception ex) {
+          if (!(ex instanceof CalciteContextException)) {
+            throw ex;
+          }
+          if (validator.getConformance().isSelectAlias() && id.isSimple()) {
+            // Try to lookup the item in the select list itself
+            String name = id.getSimple();
+            @Nullable SqlNode expr = null;
+            final SqlNameMatcher nameMatcher =
+                validator.catalogReader.nameMatcher();
+            int n = 0;

Review Comment:
   I feel that the variable name `n` is a bit vague. Is there a more 
appropriate name?



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

Reply via email to