dssysolyatin commented on code in PR #4692:
URL: https://github.com/apache/calcite/pull/4692#discussion_r2637183810
##########
core/src/main/java/org/apache/calcite/rel/rel2sql/RelToSqlConverter.java:
##########
@@ -223,6 +224,69 @@ private static class AliasReplacementShuttle extends
SqlShuttle {
}
}
+ /**
+ * Wraps a nested join Result into a subquery with a new alias.
+ * Required for dialects like ClickHouse that don't support nested JOIN
syntax.
+ *
+ * @param input the Result from the nested join subtree
+ * @param outerAlias the alias to assign to the wrapped subquery
+ * @return a new Result with the wrapped SQL node
+ */
+ protected Result wrapNestedJoin(Result input, RelNode inputRel, String
outerAlias) {
+ // Get the original SQL node from the input Result
+ final SqlNode original = input.asSelect();
+ // Generate inner alias (different from outer)
+ String innerAlias = "t" + inputRel.getId();
+ // Wrap: original → (SELECT * FROM (original) AS newAlias)
+ SqlNode wrapped = wrapAsSelectStar(original, innerAlias);
+
+ Map<String, RelDataType> newAliases = new LinkedHashMap<>();
+
+ // Add the outer alias with the correct row type
+ newAliases.put(outerAlias, inputRel.getRowType());
+
+ return new Result(
+ wrapped,
+ input.clauses,
+ outerAlias,
+ null,
+ newAliases);
+ }
+
+ /**
+ * Wraps a subquery into a SELECT * FROM (subQuery) AS alias structure.
+ *
+ * @param subQuery the original SQL node to wrap
+ * @param alias the alias to assign to the wrapped subquery
+ * @return a SqlSelect node representing: SELECT * FROM (subQuery) AS alias
+ */
+ protected SqlNode wrapAsSelectStar(SqlNode subQuery, String alias) {
Review Comment:
Can you use `SqlImplementor.wrapSelect` ?
--
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]