Steven Jacobs has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2656

Change subject: [ASTERIXDB-2391][COMP] Prevent insert return variables from 
being projected away
......................................................................

[ASTERIXDB-2391][COMP] Prevent insert return variables from being projected away

Prevent IntroduceDynamicTypeCastRule from removing variables
that may be needed elsewhere (e.g., by a returning clause)
Added test case

Change-Id: I9a86668c5c83ec2b73ceec57289211407c4ad07f
---
M 
asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.1.ddl.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.2.query.sqlpp
A 
asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue2391-returning/issue2391-returning.2.adm
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
5 files changed, 72 insertions(+), 1 deletion(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/56/2656/1

diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
index 2695337..f0db04a 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/IntroduceDynamicTypeCastRule.java
@@ -50,6 +50,7 @@
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.DelegateOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.DistributeResultOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.InsertDeleteUpsertOperator;
+import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.ProjectOperator;
 import 
org.apache.hyracks.algebricks.core.algebra.operators.logical.visitors.VariableUtilities;
 import org.apache.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 
@@ -220,7 +221,13 @@
                     opRef.setValue(newAssignOperator);
                     
context.computeAndSetTypeEnvironmentForOperator(newAssignOperator);
                     newAssignOperator.computeOutputTypeEnvironment(context);
-                    VariableUtilities.substituteVariables(parent, recordVar, 
newAssignVar, context);
+                    if (parent.getOperatorTag() == LogicalOperatorTag.PROJECT) 
{
+                        //Don't remove the variable that might be used above 
the insert
+                        ((ProjectOperator) 
parent).getVariables().add(newAssignVar);
+                        
context.computeAndSetTypeEnvironmentForOperator(parent);
+                    } else {
+                        VariableUtilities.substituteVariables(parent, 
recordVar, newAssignVar, context);
+                    }
                     return newAssignVar;
                 }
             }
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.1.ddl.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.1.ddl.sqlpp
new file mode 100644
index 0000000..68c9788
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-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  : ASTERIXDB-2391
+ * Expected Res : Success
+ * Date         : May 2018
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+create type sub as {
+  subscriptionId: uuid
+};
+
+create dataset subscriptions(sub) primary key subscriptionId;
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.2.query.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.2.query.sqlpp
new file mode 100644
index 0000000..64f1dc4
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/upsert/issue2391-returning/issue2391-returning.2.query.sqlpp
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+
+USE test;
+
+upsert into subscriptions as record(
+[ {"subscriptionId":create_uuid(), "param0": "HenryGale", 
"brokerSubscriptions":[{"brokerSubscriptionId":create_uuid(),
+ "brokerDataverse":"dataverse1","brokerName":"broker1"}]} ]
+) returning 
record.brokerSubscriptions[array_count(record.brokerSubscriptions)-1]. 
brokerName;
\ No newline at end of file
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue2391-returning/issue2391-returning.2.adm
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue2391-returning/issue2391-returning.2.adm
new file mode 100644
index 0000000..b6668a2
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/upsert/issue2391-returning/issue2391-returning.2.adm
@@ -0,0 +1 @@
+"broker1"
\ No newline at end of file
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 f972050..ba77051 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -9649,6 +9649,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="upsert">
+      <compilation-unit name="issue2391-returning">
+        <output-dir compare="Text">issue2391-returning</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="upsert">
       <compilation-unit name="nested-index">
         <output-dir compare="Text">nested-index</output-dir>
       </compilation-unit>

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2656
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9a86668c5c83ec2b73ceec57289211407c4ad07f
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Steven Jacobs <[email protected]>

Reply via email to