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 2021/09/01 17:57:47 UTC

[asterixdb] branch master updated: [NO ISSUE][COMP] Support parenthesized array constructor

This is an automated email from the ASF dual-hosted git repository.

dlych pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/asterixdb.git


The following commit(s) were added to refs/heads/master by this push:
     new e963059  [NO ISSUE][COMP] Support parenthesized array constructor
e963059 is described below

commit e9630590d621795e1d6a42af1593e79f92094c93
Author: Dmitry Lychagin <dm...@couchbase.com>
AuthorDate: Mon Aug 30 15:29:30 2021 -0700

    [NO ISSUE][COMP] Support parenthesized array constructor
    
    - user model changes: no
    - storage format changes: no
    - interface changes: no
    
    Details:
    - Add support for parenthesized array constructor:
      ( expr1, expr2, ... exprN ) when N >= 2
    - Add testcases and update documentation
    
    Change-Id: I77f0935de7abda6f4332dabe4162ced621633317
    Reviewed-on: https://asterix-gerrit.ics.uci.edu/c/asterixdb/+/13043
    Tested-by: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Integration-Tests: Jenkins <je...@fulliautomatix.ics.uci.edu>
    Reviewed-by: Dmitry Lychagin <dm...@couchbase.com>
    Reviewed-by: Ali Alsuliman <al...@gmail.com>
---
 .../ordered-list-constructor_05.1.query.sqlpp      |  31 ++++++
 ...ered-list-constructor_06_negative.1.query.sqlpp |  31 ++++++
 .../ordered-list-constructor_05.1.adm              |   2 +
 .../ordered-list-constructor_05.1.ast              | 114 +++++++++++++++++++++
 .../test/resources/runtimets/testsuite_sqlpp.xml   |  16 +++
 .../resources/runtimets/testsuite_sqlpp_parser.xml |   5 +
 asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf  |   6 +-
 .../asterix-doc/src/main/markdown/sqlpp/2_expr.md  |   3 +
 .../asterix-lang-sqlpp/src/main/javacc/SQLPP.jj    |  24 ++++-
 9 files changed, 226 insertions(+), 6 deletions(-)

diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.query.sqlpp
new file mode 100644
index 0000000..a86df20
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+select
+  r,
+  ('foo','bar','foobar') a1,
+  (r,[r],null) a2,
+  (
+    (from [r, r+1] x select value count(x)),
+    (from [r, r+1] x select value sum(x))
+  ) a3,
+  (r,[r]) = [r,[r]] eq
+
+from range(1,2) r
+order by r;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_06_negative/ordered-list-constructor_06_negative.1.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_06_negative/ordered-list-constructor_06_negative.1.query.sqlpp
new file mode 100644
index 0000000..24346b4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/list/ordered-list-constructor_06_negative/ordered-list-constructor_06_negative.1.query.sqlpp
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+/*
+ * Failure expected: need parenthesis around each subquery
+ */
+
+select
+  (
+    from [r, r+1] x select value count(x),
+    from [r, r+1] x select value sum(x)
+  ) x
+
+from range(1,2) r
+order by r;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/list/ordered-list-constructor_05/ordered-list-constructor_05.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/list/ordered-list-constructor_05/ordered-list-constructor_05.1.adm
new file mode 100644
index 0000000..466187e
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/list/ordered-list-constructor_05/ordered-list-constructor_05.1.adm
@@ -0,0 +1,2 @@
+{ "r": 1, "a1": [ "foo", "bar", "foobar" ], "a2": [ 1, [ 1 ], null ], "a3": [ [ 2 ], [ 3 ] ], "eq": true }
+{ "r": 2, "a1": [ "foo", "bar", "foobar" ], "a2": [ 2, [ 2 ], null ], "a3": [ [ 2 ], [ 5 ] ], "eq": true }
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.ast b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.ast
new file mode 100644
index 0000000..cf6bb09
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results_parser_sqlpp/list/ordered-list-constructor_05/ordered-list-constructor_05.1.ast
@@ -0,0 +1,114 @@
+Query:
+SELECT [
+Variable [ Name=$r ]
+r
+OrderedListConstructor [
+  LiteralExpr [STRING] [foo]
+  LiteralExpr [STRING] [bar]
+  LiteralExpr [STRING] [foobar]
+]
+a1
+OrderedListConstructor [
+  Variable [ Name=$r ]
+  OrderedListConstructor [
+    Variable [ Name=$r ]
+  ]
+  LiteralExpr [NULL]
+]
+a2
+OrderedListConstructor [
+  (
+    SELECT ELEMENT [
+    FunctionCall asterix.sql-count@1[
+      (
+        SELECT ELEMENT [
+        FieldAccessor [
+          Variable [ Name=#3 ]
+          Field=x
+        ]
+        ]
+        FROM [          Variable [ Name=#1 ]
+          AS Variable [ Name=#3 ]
+        ]
+      )
+    ]
+    ]
+    FROM [      OrderedListConstructor [
+        Variable [ Name=$r ]
+        OperatorExpr [
+          Variable [ Name=$r ]
+          +
+          LiteralExpr [LONG] [1]
+        ]
+      ]
+      AS Variable [ Name=$x ]
+    ]
+    Group All
+      GROUP AS Variable [ Name=#1 ]
+      (
+        x:=Variable [ Name=$x ]
+      )
+
+  )
+  (
+    SELECT ELEMENT [
+    FunctionCall asterix.sql-sum@1[
+      (
+        SELECT ELEMENT [
+        FieldAccessor [
+          Variable [ Name=#4 ]
+          Field=x
+        ]
+        ]
+        FROM [          Variable [ Name=#2 ]
+          AS Variable [ Name=#4 ]
+        ]
+      )
+    ]
+    ]
+    FROM [      OrderedListConstructor [
+        Variable [ Name=$r ]
+        OperatorExpr [
+          Variable [ Name=$r ]
+          +
+          LiteralExpr [LONG] [1]
+        ]
+      ]
+      AS Variable [ Name=$x ]
+    ]
+    Group All
+      GROUP AS Variable [ Name=#2 ]
+      (
+        x:=Variable [ Name=$x ]
+      )
+
+  )
+]
+a3
+OperatorExpr [
+  OrderedListConstructor [
+    Variable [ Name=$r ]
+    OrderedListConstructor [
+      Variable [ Name=$r ]
+    ]
+  ]
+  =
+  OrderedListConstructor [
+    Variable [ Name=$r ]
+    OrderedListConstructor [
+      Variable [ Name=$r ]
+    ]
+  ]
+]
+eq
+]
+FROM [  FunctionCall asterix.range@2[
+    LiteralExpr [LONG] [1]
+    LiteralExpr [LONG] [2]
+  ]
+  AS Variable [ Name=$r ]
+]
+Orderby
+  Variable [ Name=$r ]
+  ASC
+
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 9211032..b6d87cb 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -6689,6 +6689,22 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="list">
+      <compilation-unit name="ordered-list-constructor_04">
+        <output-dir compare="Text">ordered-list-constructor_04</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="list">
+      <compilation-unit name="ordered-list-constructor_05">
+        <output-dir compare="Text">ordered-list-constructor_05</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="list">
+      <compilation-unit name="ordered-list-constructor_06_negative">
+        <output-dir compare="Text">none</output-dir>
+        <expected-error><![CDATA[ASX1001: Syntax error: In line 26 >>    from [r, r+1] x select value count(x),<< Encountered "," at column 42]]></expected-error>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="list">
       <compilation-unit name="scan-collection_01">
         <output-dir compare="Text">scan-collection_01</output-dir>
       </compilation-unit>
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
index aff0dcd..6d85178 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp_parser.xml
@@ -2804,6 +2804,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="list">
+      <compilation-unit name="ordered-list-constructor_05">
+        <output-dir compare="AST">ordered-list-constructor_05</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="list">
       <compilation-unit name="scan-collection_01">
         <output-dir compare="AST">scan-collection_01</output-dir>
       </compilation-unit>
diff --git a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
index 805ac0a..becc4b1 100644
--- a/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
+++ b/asterixdb/asterix-doc/src/main/grammar/sqlpp.ebnf
@@ -28,8 +28,6 @@ Literal ::=  StringLiteral
 
 ParenthesizedExpr ::= ("(" Expr ")") | Subquery
 
-Subquery ::= ("(" Selection ")")
-
 FunctionCall ::= OrdinaryFunctionCall | AggregateFunctionCall | WindowFunctionCall
 
 OrdinaryFunctionCall ::= (DataverseName ".")? Identifier "(" Expr ("," Expr)* ")"
@@ -42,12 +40,14 @@ SimpleCaseExpr ::= "CASE" Expr ("WHEN" Expr "THEN" Expr)+ ("ELSE" Expr)? "END"
 
 SearchedCaseExpr ::= "CASE" ("WHEN" Expr "THEN" Expr)+ ("ELSE" Expr)? "END"
 
-Constructor ::= ObjectConstructor | ArrayConstructor | MultisetConstructor
+Constructor ::= ObjectConstructor | ArrayConstructor | ParenthesizedArrayConstructor | MultisetConstructor
 
 ObjectConstructor ::= "{" ( Expr ( ":" Expr )? ( "," Expr ( ":" Expr )? )* )? "}"
 
 ArrayConstructor ::= "[" Expr ("," Expr)* "]"
 
+ParenthesizedArrayConstructor ::= "(" Expr ("," Expr)+ ")"
+
 MultisetConstructor ::= "{{" Expr ("," Expr)* "}}"
 
 Query ::= (Expr | Selection)
diff --git a/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md b/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
index 37bd2f0..46ff6e7 100644
--- a/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
+++ b/asterixdb/asterix-doc/src/main/markdown/sqlpp/2_expr.md
@@ -408,6 +408,9 @@ The following example illustrates the form of a case expression.
 ##### ArrayConstructor
 ![](../images/diagrams/ArrayConstructor.png)
 
+##### ParenthesizedArrayConstructor
+![](../images/diagrams/ParenthesizedArrayConstructor.png)
+
 ##### MultisetConstructor
 ![](../images/diagrams/MultisetConstructor.png)
 
diff --git a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
index f3e19a3..e94ad6b 100644
--- a/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
+++ b/asterixdb/asterix-lang-sqlpp/src/main/javacc/SQLPP.jj
@@ -4265,17 +4265,35 @@ WindowExpression.FrameExclusionKind WindowFrameExclusion() throws ParseException
 
 Expression ParenthesizedExpression() throws ParseException:
 {
-  Expression expr;
+  Token startToken = null;
+  Expression expr = null, expr2 = null;
+  List<Expression> exprList = null;
 }
 {
     (
     LOOKAHEAD(2)
-    <LEFTPAREN> expr = Expression() <RIGHTPAREN>
+    <LEFTPAREN> { startToken = token; } expr = Expression()
+    (
+      <COMMA> expr2 = Expression()
+      {
+        if (exprList == null) {
+          exprList = new ArrayList<Expression>();
+          exprList.add(expr);
+        }
+        exprList.add(expr2);
+      }
+    )*
+    <RIGHTPAREN>
     |
     expr = Subquery()
     )
     {
-      return expr;
+      if (exprList != null) {
+        ListConstructor listExpr = new ListConstructor(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR, exprList);
+        return addSourceLocation(listExpr, startToken);
+      } else {
+        return expr;
+      }
     }
 }