mihaibudiu commented on code in PR #4975:
URL: https://github.com/apache/calcite/pull/4975#discussion_r3336193834


##########
core/src/main/codegen/templates/Parser.jj:
##########
@@ -5249,28 +5249,55 @@ SqlNode ArrayConstructor() :
     final String p;
 }
 {
-    <ARRAY> { s = span(); }
     (
+        <ARRAY> { s = span(); }
         (
-            // nullary array function call: "array()" (Apache Spark)
-            LOOKAHEAD(2)
-            <LPAREN> <RPAREN> { args = SqlNodeList.EMPTY; }
+            (
+                // nullary array function call: "array()" (Apache Spark)
+                LOOKAHEAD(2)
+                <LPAREN> <RPAREN> { args = SqlNodeList.EMPTY; }
+            |
+                args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_ALL)
+            )
+            {
+                if (args.size() == 1 && args.get(0).isA(SqlKind.QUERY)) {
+                    // Array query constructor, 'ARRAY (SELECT * FROM t)'
+                    return 
SqlStdOperatorTable.ARRAY_QUERY.createCall(s.end(this), args.get(0));
+                } else {
+                    // Spark ARRAY function, 'ARRAY(1, 2)',
+                    // equivalent to standard 'ARRAY [1, 2]'
+                    return SqlLibraryOperators.ARRAY.createCall(s.end(this), 
args.getList());
+                }
+            }
         |
-            args = ParenthesizedQueryOrCommaList(ExprContext.ACCEPT_ALL)
-        )
-        {
-            if (args.size() == 1 && args.get(0).isA(SqlKind.QUERY)) {
-                // Array query constructor, 'ARRAY (SELECT * FROM t)'
-                return SqlStdOperatorTable.ARRAY_QUERY.createCall(s.end(this), 
args.get(0));
-            } else {
-                // Spark ARRAY function, 'ARRAY(1, 2)',
-                // equivalent to standard 'ARRAY [1, 2]'
-                return SqlLibraryOperators.ARRAY.createCall(s.end(this), 
args.getList());
+            // by enumeration "ARRAY[e0, e1, ..., eN]"
+            <LBRACKET> // TODO: do trigraph as well ??( ??)
+            (
+                args = ExpressionCommaList(s, ExprContext.ACCEPT_SUB_QUERY)
+            |
+                { args = SqlNodeList.EMPTY; }
+            )
+            <RBRACKET>
+            {
+                return SqlStdOperatorTable.ARRAY_VALUE_CONSTRUCTOR.createCall(
+                    s.end(this), args.getList());
             }
-        }
+<#if 
(parser.includeParsingStringLiteralAsArrayLiteral!default.parser.includeParsingStringLiteralAsArrayLiteral)
 >
+        |
+            p = SimpleStringLiteral() {
+                try {
+                    return SqlParserUtil.parseArrayLiteral(p);
+                } catch (SqlParseException ex) {
+                    throw SqlUtil.newContextException(getPos(),
+                        RESOURCE.illegalArrayExpression(p));
+                }
+            }
+</#if>
+        )
     |
-        // by enumeration "ARRAY[e0, e1, ..., eN]"
-        <LBRACKET> // TODO: do trigraph as well ??( ??)
+        // BigQuery bare bracket array literal "[e0, e1, ..., eN]"
+        LOOKAHEAD({ this.conformance.allowBareBracketArrayLiteral() })
+        <LBRACKET> { s = span(); }

Review Comment:
   you can handle the empty argument list similar to the spark array 
constructor, and then the validator won't reject `[]` anymore. That is rather 
ugly, it's true, maybe we should fix the validator instead.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to