You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by dl...@apache.org on 2018/12/17 19:44:10 UTC

asterixdb git commit: [NO ISSUE] Fix subqueries for IndexAccessor syntax

Repository: asterixdb
Updated Branches:
  refs/heads/master 7b0736801 -> eb22980c3


[NO ISSUE] Fix subqueries for IndexAccessor syntax

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Fixed subqueries for IndexAccessor syntax.
- Added test cases for function and subquery calls as arguments.

Change-Id: Iba16c6c04a526aec117ca3adcb168cdd4ba916a8
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3091
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/eb22980c
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/eb22980c
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/eb22980c

Branch: refs/heads/master
Commit: eb22980c36e89758e5ab0a93fb9652e30d5ed5a4
Parents: 7b07368
Author: Hussain Towaileb <Hu...@Gmail.com>
Authored: Sat Dec 15 08:35:01 2018 +0300
Committer: Dmitry Lychagin <dm...@couchbase.com>
Committed: Mon Dec 17 11:43:51 2018 -0800

----------------------------------------------------------------------
 .../LangExpressionToPlanTranslator.java         | 27 +++++++++++-----
 .../list/get-item_03/get-item_03.1.ddl.sqlpp    | 34 ++++++++++++++++++++
 .../list/get-item_03/get-item_03.2.update.sqlpp | 26 +++++++++++++++
 .../list/get-item_03/get-item_03.3.query.sqlpp  | 29 +++++++++++++++++
 .../results/list/get-item_03/get-item_03.1.adm  |  2 ++
 .../resources/runtimets/testsuite_sqlpp.xml     |  5 +++
 .../visitor/GatherFunctionCallsVisitor.java     |  5 +++
 .../visitor/CheckSql92AggregateVisitor.java     | 10 +++++-
 8 files changed, 129 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/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 6d70ba5..c231fdf 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
@@ -728,23 +728,34 @@ class LangExpressionToPlanTranslator
     public Pair<ILogicalOperator, LogicalVariable> visit(IndexAccessor ia, Mutable<ILogicalOperator> tupSource)
             throws CompilationException {
         SourceLocation sourceLoc = ia.getSourceLocation();
-        Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(ia.getExpr(), tupSource);
+
+        // Expression pair
+        Pair<ILogicalExpression, Mutable<ILogicalOperator>> expressionPair =
+                langExprToAlgExpression(ia.getExpr(), tupSource);
         LogicalVariable v = context.newVar();
         AbstractFunctionCallExpression f;
+
+        // Index expression
+        Pair<ILogicalExpression, Mutable<ILogicalOperator>> indexPair = null;
+
         if (ia.isAny()) {
             f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.ANY_COLLECTION_MEMBER));
-            f.getArguments().add(new MutableObject<>(p.first));
-            f.setSourceLocation(sourceLoc);
+            f.getArguments().add(new MutableObject<>(expressionPair.first));
         } else {
-            Pair<ILogicalExpression, Mutable<ILogicalOperator>> indexPair =
-                    langExprToAlgExpression(ia.getIndexExpr(), tupSource);
+            indexPair = langExprToAlgExpression(ia.getIndexExpr(), expressionPair.second);
             f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.GET_ITEM));
-            f.getArguments().add(new MutableObject<>(p.first));
+            f.getArguments().add(new MutableObject<>(expressionPair.first));
             f.getArguments().add(new MutableObject<>(indexPair.first));
-            f.setSourceLocation(sourceLoc);
         }
+
+        f.setSourceLocation(sourceLoc);
         AssignOperator a = new AssignOperator(v, new MutableObject<>(f));
-        a.getInputs().add(p.second);
+
+        if (ia.isAny()) {
+            a.getInputs().add(expressionPair.second);
+        } else {
+            a.getInputs().add(indexPair.second); // NOSONAR: Called only if value exists
+        }
         a.setSourceLocation(sourceLoc);
         return new Pair<>(a, v);
     }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.1.ddl.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.1.ddl.sqlpp
new file mode 100644
index 0000000..f5237ec
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.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.
+ */
+
+drop dataverse test if exists;
+create dataverse test;
+use test;
+
+drop type testType if exists;
+create type testType as open {
+id: int64,
+groupId: int64,
+name: string,
+arrayItems: [int64],
+multisetItems: {{ int64 }}
+};
+
+drop dataset test if exists;
+create dataset test(testType) primary key id;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.2.update.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.2.update.sqlpp
new file mode 100644
index 0000000..12a761d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.2.update.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.
+ */
+
+use test;
+
+insert into test.test([
+{"id": 1, "groupId": 1, "name": "Name value", "arrayItems": [1, 2, 3], "multisetItems": {{1, 2, 3}}},
+{"id": 2, "groupId": 1, "name": "Name value", "arrayItems": [1, 2, 3, 4], "multisetItems": {{1, 2, 3, 4}}, "openArrayItems": null},
+{"id": 3, "groupId": 2, "name": "Name value", "arrayItems": [1, 2, 3, 4, 5], "multisetItems": {{1, 2, 3, 4, 5}}, "openArrayItems": [1, 2, 3]}
+]);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.3.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.3.query.sqlpp
new file mode 100644
index 0000000..8bd3ef1
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/get-item_03/get-item_03.3.query.sqlpp
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+use test;
+{
+"t1": [1, 2, 3][int32("0")],
+"t2": [1, 2, 3][double("0")],
+"t3": [1, 2, 3][[0, 1][0]],
+"t4": [1, 2, 3][(select value 2)[0]],
+"t5": [1, 2, 3][(select value id from test where id = 1)[0]]
+};

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-app/src/test/resources/runtimets/results/list/get-item_03/get-item_03.1.adm
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/list/get-item_03/get-item_03.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/list/get-item_03/get-item_03.1.adm
new file mode 100644
index 0000000..e4a212f
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/list/get-item_03/get-item_03.1.adm
@@ -0,0 +1,2 @@
+{ "t1": 1, "t2": 1, "t3": 1, "t4": 3, "t5": 2 }
+

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/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 ad08081..9efdcbb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4621,6 +4621,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="list">
+      <compilation-unit name="get-item_03">
+        <output-dir compare="Text">get-item_03</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="list">
       <compilation-unit name="len_01">
         <output-dir compare="Text">len_01</output-dir>
       </compilation-unit>

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
index 3d149fb..625d3e0c 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/visitor/GatherFunctionCallsVisitor.java
@@ -91,6 +91,11 @@ public class GatherFunctionCallsVisitor extends AbstractQueryExpressionVisitor<V
     @Override
     public Void visit(IndexAccessor ia, Void arg) throws CompilationException {
         ia.getExpr().accept(this, arg);
+
+        if (!ia.isAny()) {
+            ia.getIndexExpr().accept(this, arg);
+        }
+
         return null;
     }
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/eb22980c/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
index 6ea21a6..daf2ded 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
+++ b/asterixdb/asterix-lang-sqlpp/src/main/java/org/apache/asterix/lang/sqlpp/visitor/CheckSql92AggregateVisitor.java
@@ -118,7 +118,15 @@ public class CheckSql92AggregateVisitor extends AbstractSqlppQueryExpressionVisi
 
     @Override
     public Boolean visit(IndexAccessor ia, ILangExpression parentSelectBlock) throws CompilationException {
-        return ia.getExpr().accept(this, parentSelectBlock);
+        if (ia.getExpr().accept(this, parentSelectBlock)) {
+            return true;
+        }
+
+        if (!ia.isAny() && ia.getIndexExpr().accept(this, parentSelectBlock)) {
+            return true;
+        }
+
+        return false;
     }
 
     @Override