You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2018/11/08 18:01:01 UTC
[6/6] calcite git commit: [CALCITE-2652] SqlNode to SQL conversion
fails if the join condition references a BOOLEAN column (Zoltan Haindrich)
[CALCITE-2652] SqlNode to SQL conversion fails if the join condition references a BOOLEAN column (Zoltan Haindrich)
Previously when a join ON condition have contained an exact reference it ended up with an exception.
Close apache/calcite#899
Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/ebc43d92
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/ebc43d92
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/ebc43d92
Branch: refs/heads/master
Commit: ebc43d9288dca1990992b16a1fa8bbfdd193f939
Parents: 042fa6b
Author: Zoltan Haindrich <ki...@rxd.hu>
Authored: Thu Nov 1 23:15:57 2018 +0100
Committer: Julian Hyde <jh...@apache.org>
Committed: Thu Nov 8 10:00:37 2018 -0800
----------------------------------------------------------------------
.../org/apache/calcite/rel/rel2sql/SqlImplementor.java | 4 ++++
.../calcite/rel/rel2sql/RelToSqlConverterTest.java | 13 +++++++++++++
2 files changed, 17 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/calcite/blob/ebc43d92/core/src/main/java/org/apache/calcite/rel/rel2sql/SqlImplementor.java
----------------------------------------------------------------------
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 1de1255..99e9220 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
@@ -186,6 +186,10 @@ public abstract class SqlImplementor {
if (node.isAlwaysFalse()) {
return SqlLiteral.createBoolean(false, POS);
}
+ if (node instanceof RexInputRef) {
+ Context joinContext = leftContext.implementor().joinContext(leftContext, rightContext);
+ return joinContext.toSql(null, node);
+ }
if (!(node instanceof RexCall)) {
throw new AssertionError(node);
}
http://git-wip-us.apache.org/repos/asf/calcite/blob/ebc43d92/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
----------------------------------------------------------------------
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 7a5181e..351550a 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
@@ -61,6 +61,7 @@ import java.util.function.Function;
import static org.apache.calcite.test.Matchers.isLinux;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
/**
@@ -990,6 +991,18 @@ public class RelToSqlConverterTest {
sql(query).ok(expected);
}
+ /** Test case for
+ * <a href="https://issues.apache.org/jira/browse/CALCITE-2652">[CALCITE-2652]
+ * SqlNode to SQL conversion fails if the join condition references a BOOLEAN
+ * column</a>. */
+ @Test public void testJoinOnBoolean() {
+ final String sql = "SELECT 1\n"
+ + "from emps\n"
+ + "join emp on (emp.deptno = emps.empno and manager)";
+ final String s = sql(sql).schema(CalciteAssert.SchemaSpec.POST).exec();
+ assertThat(s, notNullValue()); // sufficient that conversion did not throw
+ }
+
@Test public void testCartesianProductWithInnerJoinSyntax() {
String query = "select * from \"department\"\n"
+ "INNER JOIN \"employee\" ON TRUE";