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


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -527,19 +527,29 @@ private boolean expandSelectItem(final SqlNode 
selectItem, SqlSelect select,
   }
 
   private static SqlNode expandExprFromJoin(SqlJoin join,
-      SqlIdentifier identifier, SelectScope scope) {
-    if (join.getConditionType() != JoinConditionType.USING) {
+      SqlIdentifier identifier, SelectScope scope, SqlValidatorImpl validator) 
{
+    if (join.getConditionType() != JoinConditionType.USING && 
!join.isNatural()) {
       return identifier;
     }
+    List<String> commonColumnNames;
+    // must be natural or using here, and cannot specify NATURAL keyword with 
USING clause
+    if (join.isNatural()) {
+      commonColumnNames = validator.deriveNaturalJoinColumnList(join);
+    } else {
+      commonColumnNames = SqlIdentifier.simpleNames((SqlNodeList) 
getCondition(join));
+    }
 
+    final boolean caseSensitive = 
validator.catalogReader.nameMatcher().isCaseSensitive();
     final Map<String, String> fieldAliases = getFieldAliases(scope);
 
-    for (String name
-        : SqlIdentifier.simpleNames((SqlNodeList) getCondition(join))) {
-      if (identifier.getSimple().equals(name)) {
+    for (String name : commonColumnNames) {
+      if (Util.matches(caseSensitive, identifier.getSimple(), name)) {

Review Comment:
   Rather than leaning on `Util.matches` and `Util.findMatch`, I wonder whether 
some of this logic could be encapsulated in a new method in `SqlNameMatcher`. 
If you can find the right abstraction the logic could perhaps be simplified,



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