julianhyde commented on code in PR #3837:
URL: https://github.com/apache/calcite/pull/3837#discussion_r1667135907


##########
core/src/main/java/org/apache/calcite/sql/validate/OrderByScope.java:
##########
@@ -74,31 +74,43 @@ public class OrderByScope extends DelegatingScope {
     // If it's a simple identifier, look for an alias.
     if (identifier.isSimple()
         && validator.config().conformance().isSortByAlias()) {
-      final String name = identifier.names.get(0);
-      final SqlValidatorNamespace selectNs =
-          validator.getNamespaceOrThrow(select);
-      final RelDataType rowType = selectNs.getRowType();
-
-      final SqlNameMatcher nameMatcher = validator.catalogReader.nameMatcher();
-      final RelDataTypeField field = nameMatcher.field(rowType, name);
-      final int aliasCount = aliasCount(nameMatcher, name);
-      if (aliasCount > 1) {
-        // More than one column has this alias.
-        throw validator.newValidationError(identifier,
-            RESOURCE.columnAmbiguous(name));
-      }
-      if (field != null && !field.isDynamicStar() && aliasCount == 1) {
-        // if identifier is resolved to a dynamic star, use 
super.fullyQualify() for such case.
-        return SqlQualified.create(this, 1, selectNs, identifier);
+      SqlQualified qualified = foo(this, select, identifier);
+      if (qualified != null) {
+        return qualified;
       }
     }
     return super.fullyQualify(identifier);
   }
 
+  // This method was refactored out of fullyQualify so that it can be shared
+  // with MeasureScope;
+  // TODO: complete refactoring (perhaps moving to DelegatingScope);
+  // note that we have removed a check for DynamicStar.
+  static @Nullable SqlQualified foo(DelegatingScope scope, SqlSelect select,

Review Comment:
   Moved to `DelegatingScope` and renamed to `qualifyUsingAlias`.



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