You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by st...@apache.org on 2024/04/19 02:44:00 UTC

(doris) branch master updated: [Fix](planner) fix create view star except and modify cast to sql (#33726)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new c6b766722be [Fix](planner) fix create view star except and modify cast to sql (#33726)
c6b766722be is described below

commit c6b766722beb669462f74b70f13745f53ed195e1
Author: feiniaofeiafei <53...@users.noreply.github.com>
AuthorDate: Fri Apr 19 10:43:54 2024 +0800

    [Fix](planner) fix create view star except and modify cast to sql (#33726)
---
 .../java/org/apache/doris/catalog/ScalarType.java  |  2 +-
 .../java/org/apache/doris/analysis/CastExpr.java   |  2 +-
 .../java/org/apache/doris/analysis/SelectStmt.java |  7 ++--
 .../analysis/CreateTableAsSelectStmtTest.java      |  4 +-
 .../doris/planner/TableFunctionPlanTest.java       |  2 +-
 .../create_view_star_except_and_cast_to_sql.out    | 11 ++++++
 .../create_view_star_except_and_cast_to_sql.groovy | 45 ++++++++++++++++++++++
 7 files changed, 64 insertions(+), 9 deletions(-)

diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
index adf064c0000..8e8a66849e2 100644
--- a/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
+++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/ScalarType.java
@@ -626,7 +626,7 @@ public class ScalarType extends Type {
                 break;
             case VARCHAR:
                 if (isWildcardVarchar()) {
-                    stringBuilder.append("VARCHAR(*)");
+                    return "VARCHAR(" + MAX_VARCHAR_LENGTH + ")";
                 } else if (Strings.isNullOrEmpty(lenStr)) {
                     stringBuilder.append("VARCHAR").append("(").append(len).append(")");
                 } else {
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
index d2437fbd95c..739901b7929 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java
@@ -213,7 +213,7 @@ public class CastExpr extends Expr {
             return getChild(0).toSql();
         }
         if (isAnalyzed) {
-            return "CAST(" + getChild(0).toSql() + " AS " + type.toString() + ")";
+            return "CAST(" + getChild(0).toSql() + " AS " + type.toSql() + ")";
         } else {
             return "CAST(" + getChild(0).toSql() + " AS "
                     + (isImplicit ? type.toString() : targetTypeDef.toSql()) + ")";
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
index 0b8e6070524..efe275c50d1 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/SelectStmt.java
@@ -541,6 +541,9 @@ public class SelectStmt extends QueryStmt {
         }
         // populate selectListExprs, aliasSMap, groupingSmap and colNames
         if (selectList.isExcept()) {
+            if (needToSql) {
+                originalExpr = new ArrayList<>();
+            }
             List<SelectListItem> items = selectList.getItems();
             TableName tblName = items.get(0).getTblName();
             if (tblName == null) {
@@ -561,10 +564,6 @@ public class SelectStmt extends QueryStmt {
             // remove excepted columns
             resultExprs.removeIf(expr -> exceptCols.contains(expr.toColumnLabel()));
             colLabels.removeIf(exceptCols::contains);
-            if (needToSql) {
-                originalExpr = Expr.cloneList(resultExprs);
-            }
-
         } else {
             if (needToSql) {
                 originalExpr = new ArrayList<>();
diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java
index ca4233e17cf..be1ddf7bc4a 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/CreateTableAsSelectStmtTest.java
@@ -688,8 +688,8 @@ public class CreateTableAsSelectStmtTest extends TestWithFeService {
         String showStr = showResultSet.getResultRows().get(0).get(1);
         Assertions.assertEquals(
                 "CREATE TABLE `varchar_len1` (\n"
-                        + "  `__literal_0` VARCHAR(*) NULL,\n"
-                        + "  `__concat_1` VARCHAR(*) NULL,\n"
+                        + "  `__literal_0` VARCHAR(65533) NULL,\n"
+                        + "  `__concat_1` VARCHAR(65533) NULL,\n"
                         + "  `userId` VARCHAR(255) NOT NULL\n"
                         + ") ENGINE=OLAP\n"
                         + "DUPLICATE KEY(`__literal_0`)\n"
diff --git a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java
index df6d4032055..c50d573de9b 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/planner/TableFunctionPlanTest.java
@@ -203,7 +203,7 @@ public class TableFunctionPlanTest {
         String sql = "explain select /*+ SET_VAR(enable_nereids_planner=false) */ k1 from db1.tbl1 where explode_split(k2, \",\");";
         String explainString = UtFrameUtils.getSQLPlanOrErrorMsg(ctx, sql);
         Assert.assertTrue(explainString,
-                explainString.contains("No matching function with signature: explode_split(VARCHAR(1), VARCHAR(*))."));
+                explainString.contains("No matching function with signature: explode_split(VARCHAR(1), VARCHAR(65533))."));
     }
 
     // test projection
diff --git a/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out b/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out
new file mode 100644
index 00000000000..86b7fd3a658
--- /dev/null
+++ b/regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out
@@ -0,0 +1,11 @@
+-- This file is automatically generated. You should know what you did if you want to edit this
+-- !test_select_star_except --
+1	1
+2	1
+3	5
+4	5
+6	\N
+
+-- !test_sql --
+v_mal_old_create_view2	CREATE VIEW `v_mal_old_create_view2` COMMENT 'VIEW' AS SELECT CAST(CAST(`a` AS TEXT) AS TIME(0)) AS `__cast_expr_0` FROM `regression_test_view_p0`.`mal_old_create_view`;	utf8mb4	utf8mb4_0900_bin
+
diff --git a/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy b/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy
new file mode 100644
index 00000000000..e22f929544b
--- /dev/null
+++ b/regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy
@@ -0,0 +1,45 @@
+// 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.
+
+suite("create_view_star_except_and_cast_to_sql") {
+    sql "SET enable_nereids_planner=false;"
+
+    sql """
+         DROP TABLE IF EXISTS mal_old_create_view
+        """
+    sql """
+        create table mal_old_create_view(pk int, a int, b int) distributed by hash(pk) buckets 10
+        properties('replication_num' = '1'); 
+        """
+
+    sql """
+        insert into mal_old_create_view values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6);
+     """
+    sql "sync"
+    sql "drop view if EXISTS v_mal_old_create_view"
+
+    sql "create view v_mal_old_create_view as select * except(a) from mal_old_create_view"
+
+    qt_test_select_star_except "select * from v_mal_old_create_view order by pk,b"
+
+    sql "drop view if EXISTS v_mal_old_create_view2"
+
+    sql "create view v_mal_old_create_view2 as select cast(cast(a as string) as time) from mal_old_create_view"
+    qt_test_sql "show create view v_mal_old_create_view2"
+    sql "select * from v_mal_old_create_view2"
+
+}
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org