You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by sj...@apache.org on 2018/06/11 22:40:25 UTC

asterixdb git commit: [COMP][ASTERIXDB-2400] Fix UNION handling in InlineAllNtsInSubplanVisitor

Repository: asterixdb
Updated Branches:
  refs/heads/master 6727f20a1 -> 63a63fd72


[COMP][ASTERIXDB-2400] Fix UNION handling in InlineAllNtsInSubplanVisitor

Makes the visitor correctly allow substitution of the input ops
for the output op in future operators
Added test

Change-Id: I8b7e3e24749ed88e27d6cd38be5584ea748f39fc
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2703
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/63a63fd7
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/63a63fd7
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/63a63fd7

Branch: refs/heads/master
Commit: 63a63fd72bb47cb651ee19db0ed528a588db402e
Parents: 6727f20
Author: Steven Glenn Jacobs <sj...@ucr.edu>
Authored: Mon Jun 11 11:29:09 2018 -0700
Committer: Steven Jacobs <sj...@ucr.edu>
Committed: Mon Jun 11 15:40:03 2018 -0700

----------------------------------------------------------------------
 .../subplan/InlineAllNtsInSubplanVisitor.java   |  4 +-
 .../upsert-case-returning.1.ddl.sqlpp           | 33 +++++++++
 .../upsert-case-returning.2.update.sqlpp        | 72 ++++++++++++++++++++
 .../upsert-case-returning.3.query.sqlpp         | 44 ++++++++++++
 .../upsert-case-returning.4.query.sqlpp         | 26 +++++++
 .../upsert-case-returning.3.adm                 |  1 +
 .../upsert-case-returning.4.adm                 |  1 +
 .../resources/runtimets/testsuite_sqlpp.xml     |  5 ++
 8 files changed, 184 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java
index a98a9f4..4d646f3 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/subplan/InlineAllNtsInSubplanVisitor.java
@@ -562,8 +562,8 @@ class InlineAllNtsInSubplanVisitor implements IQueryOperatorVisitor<ILogicalOper
         // Update the variable mappings
         List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varTriples = op.getVariableMappings();
         for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> triple : varTriples) {
-            updateInputToOutputVarMapping(triple.third, triple.first, false);
-            updateInputToOutputVarMapping(triple.second, triple.first, false);
+            updateInputToOutputVarMapping(triple.first, triple.third, false);
+            updateInputToOutputVarMapping(triple.second, triple.third, false);
         }
         return op;
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp
new file mode 100644
index 0000000..d3162f4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.1.ddl.sqlpp
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test for issue ASTERIXDB-2400
+ * Expected Res : Success
+ * Date         : Jun 2018
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type sub as {
+  subscriptionId: uuid
+};
+
+create dataset subscriptions(sub) primary key subscriptionId;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp
new file mode 100644
index 0000000..c4ba876
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.2.update.sqlpp
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test for issue ASTERIXDB-2400
+ * Expected Res : Success
+ * Date         : Jun 2018
+ */
+use test;
+
+upsert into subscriptions as record(
+(let v = (select value s from subscriptions s where param0 = "HenryGale")
+select value (CASE (array_count(v) > 0)
+WHEN true THEN
+{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0,
+"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL
+  select value val from [{"brokerSubscriptionId":create_uuid(),
+  "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)}
+ELSE
+{"subscriptionId":create_uuid(), "param0": "HenryGale",
+"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse":
+  "dataverse1","brokerName":"broker1","created":current_datetime()}]}
+END
+))
+);
+
+upsert into subscriptions as record(
+(let v = (select value s from subscriptions s where param0 = "HenryGale")
+select value (CASE (array_count(v) > 0)
+WHEN true THEN
+{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0,
+"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL
+  select value val from [{"brokerSubscriptionId":create_uuid(),
+  "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)}
+ELSE
+{"subscriptionId":create_uuid(), "param0": "HenryGale",
+"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse":
+  "dataverse1","brokerName":"broker1","created":current_datetime()}]}
+END
+))
+);
+
+upsert into subscriptions as record(
+(let v = (select value s from subscriptions s where param0 = "HenryGale")
+select value (CASE (array_count(v) > 0)
+WHEN true THEN
+{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0,
+"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL
+  select value val from [{"brokerSubscriptionId":create_uuid(),
+  "brokerDataverse":"dataverse1","brokerName":"broker1","created":current_datetime()}] val)}
+ELSE
+{"subscriptionId":create_uuid(), "param0": "HenryGale",
+"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse":
+  "dataverse1","brokerName":"broker1","created":current_datetime()}]}
+END
+))
+);
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp
new file mode 100644
index 0000000..0677150
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.3.query.sqlpp
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test for issue ASTERIXDB-2400
+ * Expected Res : Success
+ * Date         : Jun 2018
+ */
+use test;
+
+upsert into subscriptions as record(
+(let v = (select value s from subscriptions s where param0 = "HenryGale")
+select value (CASE (array_count(v) > 0)
+
+WHEN true THEN
+{"subscriptionId":v[0].subscriptionId, "param0": v[0].param0,
+"brokerSubscriptions":(select value sub from v[0].brokerSubscriptions sub UNION ALL
+  select value val from [{"brokerSubscriptionId":create_uuid(),
+  "brokerDataverse":"dataverse1","brokerName":"broker3","created":current_datetime()}] val)}
+ELSE
+{"subscriptionId":create_uuid(), "param0": "HenryGale",
+"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(), "brokerDataverse":"dataverse1",
+  "brokerName":"broker3","created":current_datetime()}]}
+END
+))
+) returning
+(let subs = record.brokerSubscriptions
+select value brokerName from subs
+order by created DESC limit 1)[0];
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp
new file mode 100644
index 0000000..51889d2
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/upsert-case-returning/upsert-case-returning.4.query.sqlpp
@@ -0,0 +1,26 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description  : Test for issue ASTERIXDB-2400
+ * Expected Res : Success
+ * Date         : Jun 2018
+ */
+use test;
+
+select value array_count(brokerSubscriptions) from subscriptions;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm
new file mode 100644
index 0000000..4dbe13c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.3.adm
@@ -0,0 +1 @@
+"broker3"
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm
new file mode 100644
index 0000000..bf0d87a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/upsert-case-returning/upsert-case-returning.4.adm
@@ -0,0 +1 @@
+4
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/63a63fd7/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 2ce8668..4376ca6 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9748,6 +9748,11 @@
         <output-dir compare="Text">multiple-secondaries</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="upsert">
+      <compilation-unit name="upsert-case-returning">
+        <output-dir compare="Text">upsert-case-returning</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="json-parser">
     <test-case FilePath="json-parser">