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/05 21:58:00 UTC

asterixdb git commit: [ASTERIXDB-2391][SQL] Insure that var for return clause gets optimized

Repository: asterixdb
Updated Branches:
  refs/heads/master 6cbc7f033 -> ee247bb54


[ASTERIXDB-2391][SQL] Insure that var for return clause gets optimized

Places the variable created for the return clause below the insert
so future optimizations can work on this variable

Added test

Change-Id: Id285435c4dc8a603c60b177dacd9f09722faac21
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2689
Sonar-Qube: Jenkins <je...@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
Contrib: 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/ee247bb5
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/ee247bb5
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/ee247bb5

Branch: refs/heads/master
Commit: ee247bb5453537128c003fc54b11850cc3c53102
Parents: 6cbc7f0
Author: Steven Glenn Jacobs <sj...@ucr.edu>
Authored: Tue Jun 5 10:07:33 2018 -0700
Committer: Steven Jacobs <sj...@ucr.edu>
Committed: Tue Jun 5 14:57:40 2018 -0700

----------------------------------------------------------------------
 .../LangExpressionToPlanTranslator.java         | 22 +++++++++----
 ...rt-returning-fieldname-qualified.1.ddl.sqlpp | 34 ++++++++++++++++++++
 ...-returning-fieldname-qualified.3.query.sqlpp | 30 +++++++++++++++++
 .../resources/runtimets/testsuite_sqlpp.xml     |  5 +++
 4 files changed, 84 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ee247bb5/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
index 2dbcb36..0c46383 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/LangExpressionToPlanTranslator.java
@@ -610,18 +610,26 @@ class LangExpressionToPlanTranslator
         }
         SourceLocation sourceLoc = compiledInsert.getSourceLocation();
 
+        //Create an assign operator that makes the variable used by the return expression
+        LogicalVariable insertedVar = context.newVar();
+        AssignOperator insertedVarAssignOperator =
+                new AssignOperator(insertedVar, new MutableObject<>(insertOp.getPayloadExpression().getValue()));
+        insertedVarAssignOperator.getInputs().add(insertOp.getInputs().get(0));
+        insertedVarAssignOperator.setSourceLocation(sourceLoc);
+        insertOp.getInputs().set(0, new MutableObject<>(insertedVarAssignOperator));
+
         // Makes the id of the insert var point to the record variable.
         context.newVarFromExpression(compiledInsert.getVar());
-        context.setVar(compiledInsert.getVar(),
-                ((VariableReferenceExpression) insertOp.getPayloadExpression().getValue()).getVariableReference());
+        context.setVar(compiledInsert.getVar(), insertedVar);
+
         Pair<ILogicalExpression, Mutable<ILogicalOperator>> p =
                 langExprToAlgExpression(returnExpression, new MutableObject<>(inputOperator));
 
-        // Adds an assign operator for the returning expression.
+        // Adds an assign operator for the result of the returning expression.
         LogicalVariable resultVar = context.newVar();
-        AssignOperator assignOperator = new AssignOperator(resultVar, new MutableObject<>(p.first));
-        assignOperator.getInputs().add(p.second);
-        assignOperator.setSourceLocation(sourceLoc);
+        AssignOperator createResultAssignOperator = new AssignOperator(resultVar, new MutableObject<>(p.first));
+        createResultAssignOperator.getInputs().add(p.second);
+        createResultAssignOperator.setSourceLocation(sourceLoc);
 
         // Adds a distribute result operator.
         List<Mutable<ILogicalExpression>> expressions = new ArrayList<>();
@@ -629,7 +637,7 @@ class LangExpressionToPlanTranslator
         ResultSetSinkId rssId = new ResultSetSinkId(metadataProvider.getResultSetId());
         ResultSetDataSink sink = new ResultSetDataSink(rssId, null);
         DistributeResultOperator distResultOperator = new DistributeResultOperator(expressions, sink);
-        distResultOperator.getInputs().add(new MutableObject<>(assignOperator));
+        distResultOperator.getInputs().add(new MutableObject<>(createResultAssignOperator));
 
         distResultOperator.setSourceLocation(sourceLoc);
         return distResultOperator;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ee247bb5/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.1.ddl.sqlpp
new file mode 100644
index 0000000..a41976b
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.1.ddl.sqlpp
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+/*
+ * Test case Name  : insert-returning-fieldname
+ * Description     : Check fields returned on insert
+ * Expected Result : Success
+ * Date            : Mar 2015
+ */
+
+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/ee247bb5/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.3.query.sqlpp
new file mode 100644
index 0000000..dad3a82
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/dml/insert-returning-fieldname-qualified/insert-returning-fieldname-qualified.3.query.sqlpp
@@ -0,0 +1,30 @@
+/*
+ * 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.
+ */
+/*
+ * Test case Name  : insert-returning-fieldname
+ * Description     : Check fields returned on insert
+ * Expected Result : Success
+ * Date            : Mar 2015
+ */
+
+use test;
+
+upsert into subscriptions as record(
+[{"subscriptionId":create_uuid(), "word": "hello"}]
+) returning record.word;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/ee247bb5/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 50c2dcc..acb544f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -1953,6 +1953,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="dml">
+      <compilation-unit name="insert-returning-fieldname-qualified">
+        <output-dir compare="Text">insert-returning-fieldname</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="dml">
       <compilation-unit name="insert-returning-fieldname-implicit">
         <output-dir compare="Text">insert-returning-fieldname</output-dir>
         <expected-error>Need an alias for the enclosed expression</expected-error>