You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by ch...@apache.org on 2022/06/06 02:12:32 UTC
[calcite] branch main updated: [CALCITE-5150] Parser should parse subquery with order by inside array constructor
This is an automated email from the ASF dual-hosted git repository.
chunwei pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/calcite.git
The following commit(s) were added to refs/heads/main by this push:
new 4a4114419 [CALCITE-5150] Parser should parse subquery with order by inside array constructor
4a4114419 is described below
commit 4a4114419b0341fa4887b4838195ef7855c00e22
Author: dssysolyatin <dm...@gmail.com>
AuthorDate: Thu May 12 11:25:37 2022 +0300
[CALCITE-5150] Parser should parse subquery with order by inside array constructor
---
core/src/main/codegen/templates/Parser.jj | 2 +-
.../main/java/org/apache/calcite/sql/parser/SqlParserTest.java | 10 ++++++++++
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj
index 1f3784522..322e1b765 100644
--- a/core/src/main/codegen/templates/Parser.jj
+++ b/core/src/main/codegen/templates/Parser.jj
@@ -4679,7 +4679,7 @@ SqlNode ArrayConstructor() :
LOOKAHEAD(1)
<LPAREN>
// by sub query "MULTISET(SELECT * FROM T)"
- e = LeafQueryOrExpr(ExprContext.ACCEPT_QUERY)
+ e = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
<RPAREN>
{
return SqlStdOperatorTable.ARRAY_QUERY.createCall(
diff --git a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
index 13996a6a5..e90b64bb2 100644
--- a/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
+++ b/testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
@@ -5312,6 +5312,16 @@ public class SqlParserTest {
.ok("(ARRAY[(ROW(1, 'a')), (ROW(2, 'b'))])");
}
+ @Test void testArrayQueryConstructor() {
+ sql("SELECT array(SELECT x FROM (VALUES(1)) x)")
+ .ok("SELECT (ARRAY ((SELECT `X`\n"
+ + "FROM (VALUES (ROW(1))) AS `X`)))");
+ sql("SELECT array(SELECT x FROM (VALUES(1)) x ORDER BY x)")
+ .ok("SELECT (ARRAY (SELECT `X`\n"
+ + "FROM (VALUES (ROW(1))) AS `X`\n"
+ + "ORDER BY `X`))");
+ }
+
@Test void testCastAsCollectionType() {
// test array type.
expr("cast(a as int array)")