xiedeyantu commented on code in PR #4548:
URL: https://github.com/apache/calcite/pull/4548#discussion_r2365931480


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -526,6 +534,45 @@ private boolean expandSelectItem(final SqlNode selectItem, 
SqlSelect select,
     return false;
   }
 
+  /**
+   * Returns true if the node is a non-aggregated, non-grouped column in 
SELECT.
+   */
+  private boolean isNonAggregatedNonGroupedColumn(SqlNode node, SqlSelect 
select) {
+    if (aggFinder.findAgg(node) != null) {
+      return false;
+    }
+
+    if (node instanceof SqlIdentifier) {
+      SqlNodeList groupList = select.getGroup();
+      if (groupList == null) {
+        return true;
+      }
+      return groupList.getList().stream()
+          .noneMatch(groupItem -> groupItem != null
+              && equalAsIdentifier((SqlIdentifier) node, groupItem));
+    }
+
+    if (node instanceof SqlCall) {
+      return ((SqlCall) node).getOperandList().stream()
+          .allMatch(operand -> isNonAggregatedNonGroupedColumn(operand, 
select));
+    } else if (node instanceof SqlLiteral) {
+      return true;
+    }
+
+    return false;
+  }
+
+  /** Determines whether two SqlIdentifier objects are equivalent. */
+  private boolean equalAsIdentifier(SqlIdentifier id1, SqlNode node2) {
+    if (!(node2 instanceof SqlIdentifier)) {

Review Comment:
   I really need to think it over again.



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