From d14e24904cf94675fbea061e645883657c1fd0d9 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Tue, 16 Apr 2024 20:07:13 +0800 Subject: [PATCH 1/3] [Fix](planner) fix create view star except and modify cast to sql --- .../org/apache/doris/analysis/CastExpr.java | 2 +- .../org/apache/doris/analysis/SelectStmt.java | 7 ++- ...reate_view_star_except_and_cast_to_sql.out | 11 +++++ ...te_view_star_except_and_cast_to_sql.groovy | 45 +++++++++++++++++++ 4 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 regression-test/data/view_p0/create_view_star_except_and_cast_to_sql.out create mode 100644 regression-test/suites/view_p0/create_view_star_except_and_cast_to_sql.groovy 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 d2437fbd95c614..739901b79295fe 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 String toSqlImpl() { 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 0b8e60705246db..efe275c50d141d 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 void analyze(Analyzer analyzer) throws UserException { } // populate selectListExprs, aliasSMap, groupingSmap and colNames if (selectList.isExcept()) { + if (needToSql) { + originalExpr = new ArrayList<>(); + } List items = selectList.getItems(); TableName tblName = items.get(0).getTblName(); if (tblName == null) { @@ -561,10 +564,6 @@ public void analyze(Analyzer analyzer) throws UserException { // 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/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 00000000000000..86b7fd3a658d6a --- /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 00000000000000..e22f929544b261 --- /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 From 71aaecd8f60d15b2121902cfd601abb7e1f0bc44 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 17 Apr 2024 11:41:42 +0800 Subject: [PATCH 2/3] change varchar wildcard to sql --- .../src/main/java/org/apache/doris/catalog/ScalarType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 67346fc21609c1..fbae7ae7b2f9f5 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 String toSql(int depth) { 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 { From df5872734a4df04f3a7cb7e020e07ebcd5928d27 Mon Sep 17 00:00:00 2001 From: feiniaofeiafei Date: Wed, 17 Apr 2024 14:23:31 +0800 Subject: [PATCH 3/3] change fe ut --- .../apache/doris/analysis/CreateTableAsSelectStmtTest.java | 4 ++-- .../java/org/apache/doris/planner/TableFunctionPlanTest.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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 ca4233e17cf2a7..be1ddf7bc4a305 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 void testVarcharLength() throws Exception { 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 df6d4032055229..c50d573de9bdad 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 void tableFunctionInWhere() throws Exception { 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