Dwrite commented on code in PR #4692:
URL: https://github.com/apache/calcite/pull/4692#discussion_r2645766735
##########
core/src/main/java/org/apache/calcite/sql/dialect/ClickHouseSqlDialect.java:
##########
@@ -404,4 +411,45 @@ private static void unparseFloor(SqlWriter writer, SqlCall
call) {
call.operand(0).unparse(writer, 0, 0);
writer.endList(frame);
}
+
+ @Override public boolean shouldWrapNestedJoin(RelNode rel) {
+ if (!(rel instanceof Join)) {
+ return false;
+ }
+ Join join = (Join) rel;
+
+ // ClickHouse primarily requires wrapping the right side of a JOIN
+ // when it contains a nested JOIN
+ return containsJoinRecursive(join.getRight());
+ }
+
+ /**
+ * Checks whether the given RelNode contains a JOIN that is directly exposed
+ * at the JOIN boundary, possibly wrapped by a small number of transparent
+ * single-input operators (e.g. Project, Filter, Sort).
+ *
+ * <p>This method intentionally does NOT perform a full tree traversal.
+ * ClickHouse only requires wrapping when a JOIN appears directly as a JOIN
input;
+ * JOINs deeper in the subtree do not trigger the restriction.
+ *
+ * <p>Therefore, a full RelVisitor is avoided here to prevent over-detection
+ * and unnecessary wrapping.
+ */
+ private static boolean containsJoinRecursive(RelNode rel) {
+ if (rel instanceof Join || rel instanceof Correlate) {
+ return true;
+ }
+
+ // Look through transparent single-input operators
+ // These don't create subquery boundaries in the SQL
+ if (rel instanceof Project
+ || rel instanceof Filter
+ || rel instanceof Sort
+ || rel instanceof Aggregate) { // Add Aggregate here
Review Comment:
sure. removed
--
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]