This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-2.0-alpha in repository https://gitbox.apache.org/repos/asf/doris.git
commit 19f7051355c125a18c670f4edc23ddb6b9f6bef6 Author: AKIRA <33112463+kikyou1...@users.noreply.github.com> AuthorDate: Fri Apr 21 14:33:35 2023 +0900 [fix](planner) Failed to create table with CTAS when multiple varchar type filed as key (#18814) Add restricton for converting varchar/char to string type, only fields that is string type and not in key desc could be convert to string type now. --- .../apache/doris/datasource/InternalCatalog.java | 8 +++- .../analysis/CreateTableAsSelectStmtTest.java | 2 +- regression-test/suites/ddl_p0/test_ctas.groovy | 49 ++++++++++++++++++++++ 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 290eddf9c1..9994b3ad08 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -43,6 +43,7 @@ import org.apache.doris.analysis.DropDbStmt; import org.apache.doris.analysis.DropPartitionClause; import org.apache.doris.analysis.DropTableStmt; import org.apache.doris.analysis.Expr; +import org.apache.doris.analysis.FunctionCallExpr; import org.apache.doris.analysis.HashDistributionDesc; import org.apache.doris.analysis.KeysDesc; import org.apache.doris.analysis.LinkDbStmt; @@ -1216,6 +1217,7 @@ public class InternalCatalog implements CatalogIf<Database> { List<String> columnNames = stmt.getColumnNames(); CreateTableStmt createTableStmt = stmt.getCreateTableStmt(); QueryStmt queryStmt = stmt.getQueryStmt(); + KeysDesc keysDesc = createTableStmt.getKeysDesc(); ArrayList<Expr> resultExprs = queryStmt.getResultExprs(); ArrayList<String> colLabels = queryStmt.getColLabels(); int size = resultExprs.size(); @@ -1237,7 +1239,11 @@ public class InternalCatalog implements CatalogIf<Database> { TypeDef typeDef; Expr resultExpr = resultExprs.get(i); Type resultType = resultExpr.getType(); - if (resultType.isStringType()) { + if (resultExpr instanceof FunctionCallExpr + && resultExpr.getType().getPrimitiveType().equals(PrimitiveType.VARCHAR)) { + resultType = ScalarType.createVarchar(65533); + } + if (resultType.isStringType() && (keysDesc == null || !keysDesc.containsCol(name))) { // Use String for varchar/char/string type, // to avoid char-length-vs-byte-length issue. typeDef = new TypeDef(ScalarType.createStringType()); 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 58fcff2c2a..9544dfc7a6 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 @@ -473,7 +473,7 @@ public class CreateTableAsSelectStmtTest extends TestWithFeService { ShowResultSet showResultSet = showCreateTableByName("test_use_key_type"); Assertions.assertEquals( "CREATE TABLE `test_use_key_type` (\n" - + " `userId` varchar(65533) NOT NULL,\n" + + " `userId` varchar(255) NOT NULL,\n" + " `username` text NOT NULL\n" + ") ENGINE=OLAP\n" + "UNIQUE KEY(`userId`)\n" diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy index 1fdb93cc58..e17b82b2ec 100644 --- a/regression-test/suites/ddl_p0/test_ctas.groovy +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -107,6 +107,51 @@ suite("test_ctas") { rowNum 6 } + sql """ + create table if not exists test_tbl_81748325 + ( + `col1` varchar(66) not null , + `col2` bigint not null , + `col3` varchar(66) not null , + `col4` varchar(42) not null , + `col5` bigint not null , + `col6` bigint not null , + `col7` datetime not null , + `col8` varchar(66) not null, + `col9` varchar(66) , + `col10` varchar(66) , + `col11` varchar(66) , + `col12` text + ) + UNIQUE KEY (`col1`,`col2`,`col3`,`col4`,`col5`,`col6`) + DISTRIBUTED BY HASH(`col4`) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + + sql """ + create table `test_tbl_3156019` + UNIQUE KEY (col4,col3,from_address,to_address) + DISTRIBUTED BY HASH (col4) BUCKETS 1 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ) + as + select + col4 as col4, + col3 as col3, + concat('0x', substring(col9, 27)) as from_address, + concat('0x', substring(col10, 27)) as to_address, + col7 as date_time, + now() as update_time, + '20230318' as pt, + col8 as amount + from test_tbl_81748325 + where col4 = '43815251' + and substring(col8, 1, 10) = '1451601'; + """ + } finally { sql """ DROP TABLE IF EXISTS test_ctas """ @@ -119,6 +164,10 @@ suite("test_ctas") { sql """ DROP TABLE IF EXISTS test_ctas_json_object1 """ sql """drop table if exists a""" + + sql """DROP TABLE IF EXISTS test_tbl_81748325""" + + sql """DROP TABLE IF EXISTS test_tbl_3156019""" } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org