calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [1/2] calcite git commit: Tests for [CALCITE-974]; can now convert INSERT, UPDATE, DELETE
Date Fri, 20 Nov 2015 20:05:56 GMT
Repository: calcite
Updated Branches:
  refs/remotes/julianhyde/master [created] 4e61eae56


Tests for [CALCITE-974]; can now convert INSERT, UPDATE, DELETE


Project: http://git-wip-us.apache.org/repos/asf/calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/calcite/commit/4e61eae5
Tree: http://git-wip-us.apache.org/repos/asf/calcite/tree/4e61eae5
Diff: http://git-wip-us.apache.org/repos/asf/calcite/diff/4e61eae5

Branch: refs/remotes/julianhyde/master
Commit: 4e61eae560f5e2e46ca96a1002522cd1a3317a4e
Parents: 737846e
Author: Julian Hyde <jhyde@apache.org>
Authored: Thu Nov 19 15:01:28 2015 -0800
Committer: Julian Hyde <jhyde@apache.org>
Committed: Thu Nov 19 17:08:20 2015 -0800

----------------------------------------------------------------------
 .../calcite/test/SqlToRelConverterTest.java     | 41 +++++++++++
 .../calcite/test/SqlToRelConverterTest.xml      | 74 ++++++++++++++++++++
 2 files changed, 115 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/4e61eae5/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
----------------------------------------------------------------------
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 dbd8a63..10cdb4e 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelConverterTest.java
@@ -1182,6 +1182,47 @@ public class SqlToRelConverterTest extends SqlToRelTestBase {
         .convertsTo("${plan}");
   }
 
+  @Test public void testDelete() {
+    sql("delete from emp")
+        .convertsTo("${plan}");
+  }
+
+  @Test public void testDeleteWhere() {
+    sql("delete from emp where deptno = 10")
+        .convertsTo("${plan}");
+  }
+
+  @Test public void testUpdate() {
+    sql("update emp set empno = empno + 1")
+        .convertsTo("${plan}");
+  }
+
+  @Test public void testUpdateSubQuery() {
+    final String sql = "update emp\n"
+        + "set empno = (\n"
+        + "  select min(empno) from emp as e where e.deptno = emp.deptno)";
+    sql(sql)
+        .convertsTo("${plan}");
+  }
+
+  @Test public void testUpdateWhere() {
+    sql("update emp set empno = empno + 1 where deptno = 10")
+        .convertsTo("${plan}");
+  }
+
+  @Ignore("CALCITE-985")
+  @Test public void testMerge() {
+    final String sql = "merge into emp as target\n"
+        + "using (select * from emp where deptno = 30) as source\n"
+        + "on target.empno = source.empno\n"
+        + "when matched then\n"
+        + "  update set sal = sal + source.sal\n"
+        + "when not matched then\n"
+        + "  insert (empno, deptno, sal)\n"
+        + "  values (source.empno, source.deptno, source.sal)";
+    sql(sql).convertsTo("${plan}");
+  }
+
   @Test public void testSelectView() {
     // translated condition: deptno = 20 and sal > 1000 and empno > 100
     sql("select * from emp_20 where empno > 100")

http://git-wip-us.apache.org/repos/asf/calcite/blob/4e61eae5/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
----------------------------------------------------------------------
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 e145812..4500149 100644
--- a/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
+++ b/core/src/test/resources/org/apache/calcite/test/SqlToRelConverterTest.xml
@@ -2557,4 +2557,78 @@ LogicalProject(A=[$0], *=[$1])
 ]]>
         </Resource>
     </TestCase>
+    <TestCase name="testDeleteWhere">
+        <Resource name="sql">
+            <![CDATA[delete from emp where deptno = 10]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[DELETE], updateColumnList=[[]],
flattened=[true])
+  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8])
+    LogicalFilter(condition=[=($7, 10)])
+      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testUpdateWhere">
+        <Resource name="sql">
+            <![CDATA[update emp set empno = empno + 1 where deptno = 10]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[UPDATE], updateColumnList=[[EMPNO]],
flattened=[true])
+  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], EXPR$0=[+($0, 1)])
+    LogicalFilter(condition=[=($7, 10)])
+      LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testDelete">
+        <Resource name="sql">
+            <![CDATA[delete from emp]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[DELETE], updateColumnList=[[]],
flattened=[true])
+  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8])
+    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testUpdate">
+        <Resource name="sql">
+            <![CDATA[update emp set empno = empno + 1]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[UPDATE], updateColumnList=[[EMPNO]],
flattened=[true])
+  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], EXPR$0=[+($0, 1)])
+    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
+    <TestCase name="testUpdateSubQuery">
+        <Resource name="sql">
+            <![CDATA[update emp
+set empno = (
+  select min(empno) from emp as e where e.deptno = emp.deptno)]]>
+        </Resource>
+        <Resource name="plan">
+            <![CDATA[
+LogicalTableModify(table=[[CATALOG, SALES, EMP]], operation=[UPDATE], updateColumnList=[[EMPNO]],
flattened=[true])
+  LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], EXPR$0=[$9])
+    LogicalProject(EMPNO=[$0], ENAME=[$1], JOB=[$2], MGR=[$3], HIREDATE=[$4], SAL=[$5], COMM=[$6],
DEPTNO=[$7], SLACKER=[$8], EXPR$0=[$10])
+      LogicalJoin(condition=[=($7, $9)], joinType=[left])
+        LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+        LogicalAggregate(group=[{0}], EXPR$0=[MIN($1)])
+          LogicalProject(DEPTNO0=[$1], EMPNO=[$0])
+            LogicalProject(EMPNO=[$0], DEPTNO0=[$9])
+              LogicalJoin(condition=[=($7, $9)], joinType=[inner])
+                LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+                LogicalAggregate(group=[{0}])
+                  LogicalProject(DEPTNO=[$7])
+                    LogicalTableScan(table=[[CATALOG, SALES, EMP]])
+]]>
+        </Resource>
+    </TestCase>
 </Root>


Mime
View raw message