This is an automated email from the ASF dual-hosted git repository.
chunwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/master by this push:
new 7625938 [CALCITE-3229] UnsupportedOperationException for UPDATE with
IN query
7625938 is described below
commit 7625938f1faa37fe34540d3a7a2257ec7eae5704
Author: Chunwei Lei <[email protected]>
AuthorDate: Tue Aug 6 10:18:07 2019 +0800
[CALCITE-3229] UnsupportedOperationException for UPDATE with IN query
---
.../apache/calcite/sql2rel/SqlToRelConverter.java | 9 +++--
.../apache/calcite/test/SqlToRelConverterTest.java | 20 +++++++++++
.../apache/calcite/test/SqlToRelConverterTest.xml | 40 ++++++++++++++++++++++
3 files changed, 66 insertions(+), 3 deletions(-)
diff --git
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 1791827..58475f4 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -1800,9 +1800,12 @@ public class SqlToRelConverter {
case ALL:
switch (logic) {
case TRUE_FALSE_UNKNOWN:
- if (validator.getValidatedNodeType(node).isNullable()) {
- break;
- } else if (true) {
+ RelDataType type = validator.getValidatedNodeTypeIfKnown(node);
+ if (type == null) {
+ // The node might not be validated if we still don't know type of
the node.
+ // Therefore return directly.
+ return;
+ } else {
break;
}
// fall through
diff --git
a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
index a7d2ae5..57e634c 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -2187,6 +2187,26 @@ public class SqlToRelConverterTest extends
SqlToRelTestBase {
sql(sql).ok();
}
+ /**
+ * Test case for
+ * <a
href="https://issues.apache.org/jira/browse/CALCITE-3229">[CALCITE-3229]
+ * UnsupportedOperationException for UPDATE with IN query</a>.
+ */
+ @Test public void testUpdateSubQueryWithIn() {
+ final String sql = "update emp\n"
+ + "set empno = 1 where empno in (\n"
+ + " select empno from emp where empno=2)";
+ sql(sql).ok();
+ }
+
+ /** Similar to {@link #testUpdateSubQueryWithIn()} but with not in instead
of in. */
+ @Test public void testUpdateSubQueryWithNotIn() {
+ final String sql = "update emp\n"
+ + "set empno = 1 where empno not in (\n"
+ + " select empno from emp where empno=2)";
+ sql(sql).ok();
+ }
+
@Test public void testUpdateWhere() {
final String sql = "update emp set empno = empno + 1 where deptno = 10";
sql(sql).ok();
diff --git
a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
index 86a4273..f78b557 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -4670,6 +4670,46 @@ LogicalTableModify(table=[[CATALOG, SALES, EMP]],
operation=[UPDATE], updateColu
]]>
</Resource>
</TestCase>
+ <TestCase name="testUpdateSubQueryWithIn">
+ <Resource name="sql">
+ <![CDATA[update emp
+set empno = 1 where empno in (
+ select empno from emp where empno=2)]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[UPDATE],
updateColumnList=[[EMPNO]], sourceExpressionList=[[1]], flattened=[true])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EXPR$0=[1])
+ LogicalJoin(condition=[=($0, $9)], joinType=[inner])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalAggregate(group=[{0}])
+ LogicalProject(EMPNO=[$0])
+ LogicalFilter(condition=[=($0, 2)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
+ <TestCase name="testUpdateSubQueryWithNotIn">
+ <Resource name="sql">
+ <![CDATA[update emp
+set empno = 1 where empno not in(
+ select empno from emp where empno=2)]]>
+ </Resource>
+ <Resource name="plan">
+ <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[UPDATE],
updateColumnList=[[EMPNO]], sourceExpressionList=[[1]], flattened=[true])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4],
SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EXPR$0=[1])
+ LogicalFilter(condition=[NOT(AND(IS TRUE($11), IS NOT NULL($9)))])
+ LogicalJoin(condition=[=($9, $10)], joinType=[left])
+ LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3],
HIREDATE=[$4], SAL=[$5], COMM=[$6], DEPTNO=[$7], SLACKER=[$8], EMPNO0=[$0])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+ LogicalAggregate(group=[{0}], agg#0=[MIN($1)])
+ LogicalProject(EMPNO=[$0], $f1=[true])
+ LogicalFilter(condition=[=($0, 2)])
+ LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+ </Resource>
+ </TestCase>
<TestCase name="testOffset0">
<Resource name="sql">
<![CDATA[select * from emp offset 0]]>