Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](planner) fix create view star except and modify cast to sql #33726

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) + ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<SelectListItem> items = selectList.getItems();
TableName tblName = items.get(0).getTblName();
if (tblName == null) {
Expand All @@ -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<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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"

}
Loading