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 80eed81a4280f5f24fcefe3a471f978b56bf8311
Author: Pxl <[email protected]>
AuthorDate: Fri Aug 18 11:50:18 2023 +0800

    [Chore](parser) fix create view failed when view contained cast as varchar 
(#23043)
    
    fix create view failed when view contained cast as varchar
---
 .../antlr4/org/apache/doris/nereids/DorisParser.g4 |  3 +-
 fe/fe-core/src/main/cup/sql_parser.cup             |  2 +
 .../main/java/org/apache/doris/alter/Alter.java    |  4 +-
 .../main/java/org/apache/doris/catalog/Env.java    |  2 +-
 .../main/java/org/apache/doris/catalog/View.java   |  6 +-
 regression-test/data/view_p0/view_p0.out           |  7 --
 regression-test/suites/view_p0/view_p0.groovy      | 87 +---------------------
 7 files changed, 9 insertions(+), 102 deletions(-)

diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 
b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
index b688955a10..e63d5d9f88 100644
--- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
+++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4
@@ -452,8 +452,7 @@ unitIdentifier
     ;
 
 dataType
-    : identifier (LEFT_PAREN INTEGER_VALUE
-      (COMMA INTEGER_VALUE)* RIGHT_PAREN)?                      
#primitiveDataType
+    : identifier (LEFT_PAREN (ASTERISK | INTEGER_VALUE (COMMA INTEGER_VALUE)*) 
RIGHT_PAREN)?     #primitiveDataType
     ;
 
 // this rule is used for explicitly capturing wrong identifiers such as 
test-table, which should actually be `test-table`
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 89fdac5241..b5d64453f9 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -6174,6 +6174,8 @@ type ::=
   {: ScalarType type = ScalarType.createVarcharType(lenStr);
      RESULT = type;
   :}
+  | KW_VARCHAR LPAREN STAR RPAREN
+  {: RESULT = ScalarType.createVarcharType(-1); :}
   | KW_VARCHAR
   {: RESULT = ScalarType.createVarcharType(-1); :}
   | KW_ARRAY LESSTHAN type:value_type GREATERTHAN
diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java 
b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
index 34f8a0b991..596f76243c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
@@ -683,7 +683,7 @@ public class Alter {
                 try {
                     view.init();
                 } catch (UserException e) {
-                    throw new DdlException("failed to init view stmt", e);
+                    throw new DdlException("failed to init view stmt, reason=" 
+ e.getMessage());
                 }
                 view.setNewFullSchema(newFullSchema);
                 String viewName = view.getName();
@@ -719,7 +719,7 @@ public class Alter {
             try {
                 view.init();
             } catch (UserException e) {
-                throw new DdlException("failed to init view stmt", e);
+                throw new DdlException("failed to init view stmt, reason=" + 
e.getMessage());
             }
             view.setNewFullSchema(newFullSchema);
 
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 368f8a506a..b659a16577 100755
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -4730,7 +4730,7 @@ public class Env {
         try {
             newView.init();
         } catch (UserException e) {
-            throw new DdlException("failed to init view stmt", e);
+            throw new DdlException("failed to init view stmt, reason=" + 
e.getMessage());
         }
 
         if (!((Database) db).createTableWithLock(newView, false, 
stmt.isSetIfNotExists()).first) {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
index c072c639eb..bc2608d7b6 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/View.java
@@ -168,13 +168,11 @@ public class View extends Table {
         try {
             node = (ParseNode) SqlParserUtils.getFirstStmt(parser);
         } catch (Exception e) {
-            LOG.info("stmt is {}", inlineViewDef);
-            LOG.info("exception because: ", e);
-            LOG.info("msg is {}", inlineViewDef);
             // Do not pass e as the exception cause because it might reveal 
the existence
             // of tables that the user triggering this load may not have 
privileges on.
             throw new UserException(
-                    String.format("Failed to parse view-definition statement 
of view: %s", name));
+                    String.format("Failed to parse view-definition statement 
of view: %s, stmt is %s, reason is %s",
+                            name, inlineViewDef, e.getMessage()));
         }
         // Make sure the view definition parses to a query statement.
         if (!(node instanceof QueryStmt)) {
diff --git a/regression-test/data/view_p0/view_p0.out 
b/regression-test/data/view_p0/view_p0.out
index ff952fdaa7..d665718ba0 100644
--- a/regression-test/data/view_p0/view_p0.out
+++ b/regression-test/data/view_p0/view_p0.out
@@ -8,10 +8,3 @@
 -- !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
-
--- !sql --
-960
-
diff --git a/regression-test/suites/view_p0/view_p0.groovy 
b/regression-test/suites/view_p0/view_p0.groovy
index 963760276b..0d513cff55 100644
--- a/regression-test/suites/view_p0/view_p0.groovy
+++ b/regression-test/suites/view_p0/view_p0.groovy
@@ -37,90 +37,5 @@ 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;"
-
-    sql "drop view if exists test_element_at_view"
-
-    sql "drop view if exists test_time_diff"
-
-    sql "create view test_time_diff as select minutes_diff('2023-01-16 
10:05:04', '2023-01-15 18:05:04')"
-
-    qt_sql "select * from test_time_diff"
-
-    sql "drop view if exists test_time_diff"
-    
+    qt_sql "select cast( id as varchar(*)) from test_view_table;"
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to