This is an automated email from the ASF dual-hosted git repository.
xiong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new e822bc9dc0 [CALCITE-7050] Invalid unparse for FULL JOIN in MySQLDialect
e822bc9dc0 is described below
commit e822bc9dc0ec62fd051a318636f5b822e556831d
Author: xuzifu666 <[email protected]>
AuthorDate: Wed Jul 2 16:17:54 2025 +0800
[CALCITE-7050] Invalid unparse for FULL JOIN in MySQLDialect
---
.../apache/calcite/rel/rel2sql/SqlImplementor.java | 14 ++++++++---
.../calcite/rel/rel2sql/RelToSqlConverterTest.java | 28 ++++++++++++++++++++++
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
index 6b14b3d0e0..df60328908 100644
--- a/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
+++ b/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
@@ -34,6 +34,7 @@
import org.apache.calcite.rel.core.Project;
import org.apache.calcite.rel.core.Window;
import org.apache.calcite.rel.rules.AggregateProjectConstantToDummyJoinRule;
+import org.apache.calcite.rel.rules.FullToLeftAndRightJoinRule;
import org.apache.calcite.rel.type.RelDataType;
import org.apache.calcite.rel.type.RelDataTypeFactory;
import org.apache.calcite.rel.type.RelDataTypeField;
@@ -182,10 +183,17 @@ protected SqlImplementor(SqlDialect dialect) {
/** Visits a relational expression that has no parent. */
public final Result visitRoot(RelNode r) {
RelNode best;
- if (!this.dialect.supportsGroupByLiteral()) {
+ if (!this.dialect.supportsGroupByLiteral()
+ || !this.dialect.supportsJoinType(JoinRelType.FULL)) {
HepProgramBuilder hepProgramBuilder = new HepProgramBuilder();
- hepProgramBuilder.addRuleInstance(
- AggregateProjectConstantToDummyJoinRule.Config.DEFAULT.toRule());
+ if (!this.dialect.supportsGroupByLiteral()) {
+ hepProgramBuilder.addRuleInstance(
+ AggregateProjectConstantToDummyJoinRule.Config.DEFAULT.toRule());
+ }
+ if (!this.dialect.supportsJoinType(JoinRelType.FULL)) {
+ hepProgramBuilder.addRuleInstance(
+ FullToLeftAndRightJoinRule.Config.DEFAULT.toRule());
+ }
HepPlanner hepPlanner = new HepPlanner(hepProgramBuilder.build());
hepPlanner.setRoot(r);
diff --git
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index eef59a3109..b400b85a04 100644
---
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -10136,6 +10136,34 @@ private void checkLiteral2(String expression, String
expected) {
sql(sql).ok(expected);
}
+ /** Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-7050">[CALCITE-7050]
+ * Invalid unparse for FULL JOIN in MySQLDialect</a>. */
+ @Test void testUnsupportedFullJoin() {
+ // MySQL full join would transform to left join union right join
+ String sql = "select e1.\"salary\",e2.\"department_id\" from\n"
+ + "(select \"salary\", \"department_id\" from \"employee\") as e1\n"
+ + " full join "
+ + "(select \"salary\", \"department_id\" from \"employee\") as e2\n"
+ + "on e1.\"department_id\"=e2.\"department_id\"";
+ String query = "SELECT `salary`, `department_id0` AS `department_id`\n"
+ + "FROM (SELECT *\n"
+ + "FROM (SELECT `salary`, `department_id`\n"
+ + "FROM `foodmart`.`employee`) AS `t`\n"
+ + "LEFT JOIN (SELECT `salary`, `department_id`\n"
+ + "FROM `foodmart`.`employee`) AS `t0` ON `t`.`department_id` =
`t0`.`department_id`\n"
+ + "UNION ALL\n"
+ + "SELECT `t1`.`salary` AS `salary`, `t1`.`department_id` AS
`department_id`, "
+ + "`t2`.`salary` AS `salary0`, `t2`.`department_id` AS
`department_id0`\n"
+ + "FROM (SELECT `salary`, `department_id`\n"
+ + "FROM `foodmart`.`employee`) AS `t1`\n"
+ + "RIGHT JOIN (SELECT `salary`, `department_id`\n"
+ + "FROM `foodmart`.`employee`) AS `t2`"
+ + " ON `t1`.`department_id` = `t2`.`department_id`\n"
+ + "WHERE `t1`.`department_id` <> `t2`.`department_id`) AS `t4`";
+ sql(sql).withMysql().ok(query);
+ }
+
/** Test case for
* <a
href="https://issues.apache.org/jira/browse/CALCITE-6940">[CALCITE-6940]
* Hive/Phoenix Dialect should not cast to REAL type directly</a>,