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


##########
core/src/main/java/org/apache/calcite/sql/validate/SqlValidatorImpl.java:
##########
@@ -1538,6 +1550,52 @@ private void handleOffsetFetch(@Nullable SqlNode offset, 
@Nullable SqlNode fetch
     }
   }
 
+  /**
+   * Rewrites SELECT ... BY syntax into SELECT, GROUP BY, ORDER BY.
+   */
+  private void rewriteSelectBy(SqlSelect select) {
+    final SqlNodeList by = select.getBy();
+    if (by == null) {
+      return;
+    }
+    if (select.getGroup() != null && !select.getGroup().isEmpty()) {
+      throw newValidationError(select.getGroup(), 
RESOURCE.selectByAndGroupBy());
+    }
+    if (select.getOrderList() != null && !select.getOrderList().isEmpty()) {
+      throw newValidationError(select.getOrderList(), 
RESOURCE.selectByAndOrderBy());
+    }
+    // Mark this select as having a BY clause, so that we can enable
+    // non-strict GROUP BY behavior (wrapping non-grouped columns in 
ANY_VALUE).
+    selectsWithBy.add(select);
+
+    final SqlNodeList selectList = select.getSelectList();
+    final SqlNodeList groupBy = new SqlNodeList(by.getParserPosition());
+    final SqlNodeList orderBy = new SqlNodeList(by.getParserPosition());
+
+    // Process BY items
+    List<SqlNode> extraSelectItems = new ArrayList<>();

Review Comment:
   I refactored the code, rewriting the BY in parsing layer, and made this 
feature supported only at the Babel level.



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