You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by kx...@apache.org on 2023/08/21 14:10:37 UTC
[doris] 04/05: [Fix](View)Use the element_at function to replace %element_extract% to prevent parsing errors (#23093)
This is an automated email from the ASF dual-hosted git repository.
kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git
commit 40e69c209a8d599559a85dbf32a50496715c73b8
Author: Calvin Kirs <ac...@163.com>
AuthorDate: Mon Aug 21 11:19:10 2023 +0800
[Fix](View)Use the element_at function to replace %element_extract% to prevent parsing errors (#23093)
---
fe/fe-core/src/main/cup/sql_parser.cup | 6 +--
regression-test/data/view_p0/view_p0.out | 7 +++
regression-test/suites/view_p0/view_p0.groovy | 75 +++++++++++++++++++++++++++
3 files changed, 85 insertions(+), 3 deletions(-)
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup
index befa24e907..89fdac5241 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -6984,7 +6984,7 @@ column_subscript ::=
{: ArrayList<Expr> list = new ArrayList<Expr>();
list.add(e);
list.add(index);
- RESULT = new FunctionCallExpr("%element_extract%", list);
+ RESULT = new FunctionCallExpr("element_at", list);
:}
;
@@ -6993,14 +6993,14 @@ column_slice ::=
{: ArrayList<Expr> list = new ArrayList<Expr>();
list.add(e);
list.add(offset);
- RESULT = new FunctionCallExpr("%element_slice%", list);
+ RESULT = new FunctionCallExpr("array_slice", list);
:}
| expr:e LBRACKET expr:offset COLON expr:length RBRACKET
{: ArrayList<Expr> list = new ArrayList<Expr>();
list.add(e);
list.add(offset);
list.add(length);
- RESULT = new FunctionCallExpr("%element_slice%", list);
+ RESULT = new FunctionCallExpr("array_slice", list);
:}
;
diff --git a/regression-test/data/view_p0/view_p0.out b/regression-test/data/view_p0/view_p0.out
index 1593deb5d1..a90e1f9623 100644
--- a/regression-test/data/view_p0/view_p0.out
+++ b/regression-test/data/view_p0/view_p0.out
@@ -5,3 +5,10 @@
-- !sql --
1
+-- !sql --
+1
+
+-- !sql --
+1 2023-08-01 DORID_FIELD1 DORID_FIELD2 ["cat", "dog"] cat
+1 2023-08-01 DORID_FIELD1 DORID_FIELD2 ["cat", "dog"] dog
+
diff --git a/regression-test/suites/view_p0/view_p0.groovy b/regression-test/suites/view_p0/view_p0.groovy
index df65e24212..a6f20d4102 100644
--- a/regression-test/suites/view_p0/view_p0.groovy
+++ b/regression-test/suites/view_p0/view_p0.groovy
@@ -37,5 +37,80 @@ suite("view_p0") {
"""
qt_sql "select * from test_varchar_view;"
+ qt_sql "select cast( id as varchar(*)) from test_view_table;"
+
+ // array view
+ sql """DROP TABLE IF EXISTS test_array_tbl_1"""
+
+ sql """
+ CREATE TABLE `test_array_tbl_1` (
+ `id` int(11) NULL COMMENT "",
+ `field1` DATEV2,
+ `field2` varchar(1000),
+ `field3` varchar(1000),
+ `field4` ARRAY<STRING>,
+ `field5` ARRAY<STRING>
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`id`)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+
+ sql """DROP TABLE IF EXISTS test_array_tbl_2"""
+ sql """
+ CREATE TABLE `test_array_tbl_2` (
+ `id` int(11) NULL COMMENT "",
+ `field1` DATEV2,
+ `field2` varchar(1000),
+ `field3` varchar(1000),
+ `field4` ARRAY<STRING>,
+ `field5` ARRAY<STRING>
+ ) ENGINE=OLAP
+ DUPLICATE KEY(`id`)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`id`) BUCKETS 1
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ );
+ """
+ sql """INSERT into test_array_tbl_1 values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
+
+ sql """INSERT into test_array_tbl_2 values(1,'2023-08-01',"DORID_FIELD1","DORID_FIELD2",["cat","dog"],["cat","dog"])"""
+
+ sql """DROP VIEW IF EXISTS test_element_at_view"""
+
+ sql """
+ CREATE VIEW test_element_at_view AS
+ SELECT id, dm, pn, field3, ms, ek[sm] AS ek
+ FROM
+ (
+ SELECT
+ id, dm, pn, field3, ek, ms, tmp,
+ SUM(tmp) OVER (PARTITION BY id, dm, pn, field3 ORDER BY id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS sm
+ FROM
+ (
+ SELECT
+ a.id AS id,
+ a.field1 AS dm,
+ a.field2 AS pn,
+ field3,
+ field4 AS ek,
+ field5 AS ms,
+ 1 AS tmp
+ FROM
+ (
+ SELECT * FROM test_array_tbl_1 LATERAL VIEW explode(field4) test_array_tbl_2 AS mension
+ ) a
+ ) b
+ ) c;
+ """
+ qt_sql "select * from test_element_at_view;"
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org