From 34bd5df24a0359f56d9727dc36e84f5dc390235d Mon Sep 17 00:00:00 2001 From: feiniaofeiafei <53502832+feiniaofeiafei@users.noreply.github.com> Date: Thu, 11 Jul 2024 10:49:14 +0800 Subject: [PATCH 1/4] [Fix](planner) fix bug of char(255) toSql (#37340) --- .../org/apache/doris/catalog/ScalarType.java | 4 +- .../doris/catalog/CreateFunctionTest.java | 5 + .../ddl_p0/test_create_table_like_nereids.out | 26 +++++ .../schema_change_modify_mv_column_type.out | 103 ++++++++++++++++++ .../test_create_table_like_nereids.groovy | 101 +++++++++++++++++ 5 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 regression-test/data/ddl_p0/test_create_table_like_nereids.out create mode 100644 regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out create mode 100644 regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy 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 b4a81068b3f270..6f684471e56c6f 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 @@ -578,7 +578,7 @@ public static ScalarType createHllType() { public String toString() { if (type == PrimitiveType.CHAR) { if (isWildcardChar()) { - return "CHARACTER"; + return "CHARACTER(" + MAX_CHAR_LENGTH + ")"; } return "CHAR(" + len + ")"; } else if (type == PrimitiveType.DECIMALV2) { @@ -614,7 +614,7 @@ public String toSql(int depth) { switch (type) { case CHAR: if (isWildcardChar()) { - stringBuilder.append("CHARACTER"); + stringBuilder.append("CHARACTER").append("(").append(MAX_CHAR_LENGTH).append(")"); } else if (Strings.isNullOrEmpty(lenStr)) { stringBuilder.append("CHAR").append("(").append(len).append(")"); } else { diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java index 7c9a45febaea3f..4781a7e6a668a7 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java @@ -285,7 +285,12 @@ public void testCreateGlobalFunction() throws Exception { testFunctionQuery(ctx, queryStr, true); queryStr = "select to_char(k1, 4) from db2.tbl1;"; +<<<<<<< HEAD Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("CAST(`k1` AS CHARACTER)")); +======= + Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), + "CAST(`k1` AS CHARACTER(255))")); +>>>>>>> a317eba747 ([Fix](planner) fix bug of char(255) toSql (#37340)) } private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception { diff --git a/regression-test/data/ddl_p0/test_create_table_like_nereids.out b/regression-test/data/ddl_p0/test_create_table_like_nereids.out new file mode 100644 index 00000000000000..137a4aa9466b4e --- /dev/null +++ b/regression-test/data/ddl_p0/test_create_table_like_nereids.out @@ -0,0 +1,26 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !test_without_roll_up -- +1 1 2 +1 1 4 +1 3 6 +2 1 3 +2 1 4 +2 1 7 +2 3 5 +2 3 9 +2 4 2 +3 2 8 +3 5 \N +3 5 6 +3 5 6 +3 5 8 +4 5 6 +6 \N 6 +6 7 1 + +-- !test_char_255 -- +0 + +-- !select -- +123 abcdddddd + diff --git a/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out b/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out new file mode 100644 index 00000000000000..1cf151dc70c8bf --- /dev/null +++ b/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out @@ -0,0 +1,103 @@ +-- This file is automatically generated. You should know what you did if you want to edit this +-- !sql -- +tbl_scalar_types_dup DUP_KEYS k1 BIGINT BIGINT Yes true \N true + c_bool BOOLEAN BOOLEAN Yes false \N NONE true + c_tinyint TINYINT TINYINT Yes false \N NONE true + c_smallint SMALLINT SMALLINT Yes false \N NONE true + c_int INT INT Yes false \N NONE true + c_bigint BIGINT BIGINT Yes false \N NONE true + c_largeint LARGEINT LARGEINT Yes false \N NONE true + c_float FLOAT FLOAT Yes false \N NONE true + c_double DOUBLE DOUBLE Yes false \N NONE true + c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true + c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true + c_date DATE DATEV2 Yes false \N NONE true + c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true + c_datev2 DATE DATEV2 Yes false \N NONE true + c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true + c_char CHAR(15) CHAR(15) Yes false \N NONE true + c_varchar VARCHAR(100) VARCHAR(100) Yes false \N NONE true + c_string TEXT TEXT Yes false \N NONE true + +mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N true `c_tinyint` + mv_c_bool BOOLEAN BOOLEAN Yes true \N true `c_bool` + mv_k1 BIGINT BIGINT Yes true \N true `k1` + mv_c_smallint SMALLINT SMALLINT Yes false \N NONE true `c_smallint` + mv_c_int INT INT Yes false \N NONE true `c_int` + mv_c_bigint BIGINT BIGINT Yes false \N NONE true `c_bigint` + mv_c_largeint LARGEINT LARGEINT Yes false \N NONE true `c_largeint` + mv_c_float FLOAT FLOAT Yes false \N NONE true `c_float` + mv_c_double DOUBLE DOUBLE Yes false \N NONE true `c_double` + mv_c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimal` + mv_c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimalv3` + mv_c_date DATE DATEV2 Yes false \N NONE true `c_date` + mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` + mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` + mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` + mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` + mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` + mv_c_string TEXT TEXT Yes false \N NONE true `c_string` + +-- !sql -- +-2147475406 true 45 23794 -11023 915989078 2115356192 15927.068 1.392557423391501E9 45951348783208518.810 8340516346665031.310 2022-01-26 2022-04-13T11:13:48 2022-01-31 2022-02-16T06:07:21 130.50.6.0 DeniseMatthews@Yozio.mil Londonderry Alley 61 +-2147424303 false -28 -5177 -1409 149417728 553396597 -10123.558 -1.268722910924068E9 67354830622005524.848 52407243294991364.348 2022-06-29 2022-05-06T09:30:02 2023-01-09 2022-03-12T14:26 109.50.92.119 CraigHughes@Talane.biz Heath Drive 38 +-2147413967 true -75 30533 -5435 -727385447 32929830 9577.564 1.334766997510087E9 39973144022098028.800 5886463393340733.108 2022-06-23 2022-05-10T19:13:50 2022-01-17 2022-11-26T22:49:36 157.38.90.25 JoshuaLewis@Jayo.mil Loeprich Crossing 43 +-2147380173 true -79 -5785 9752 1851350218 1121852298 25652.402 -1.618061059513558E9 95821873014545736.897 38923569966532828.626 2022-10-30 2022-05-02T17:06:33 2022-08-11 2022-02-08T10:19:47 217.198.98.239 JoseBoyd@Voonder.info Lawn Lane 78 +-2147374459 false -118 -30267 -14606 262497842 -1811881704 8211.805 2.37851933046663E8 37354136531251060.755 63024710145324035.720 2022-10-11 2022-01-17T10:20:18 2022-04-12 2022-10-24T18:14:38 16.243.195.81 BrendaBoyd@Talane.net Annamark Pass 72 +-2147369329 false -121 -22859 4733 -378861997 385323541 -22969.846 1.483825622420542E9 50940877800950041.950 87108729227937387.294 2022-06-05 2022-08-18T05:39:56 2022-08-21 2022-12-12T08:43:59 16.27.107.167 PhyllisSmith@Zoombox.org Village Green Terrace 55 +-2147367329 true 84 21471 -29331 1823545950 1200800855 -13832.219 8.01505090724918E8 45495296019797580.477 45196001436348967.557 2022-02-17 2022-05-23T01:44:31 2022-08-01 2022-08-16T10:32:36 84.110.209.128 vLane@Dablist.edu Packers Street 34 +-2147339287 true 62 28989 -32018 650184880 -365849435 -21644.414 -7.8648426469503E7 92593387160450273.870 39588697152489527.185 2022-07-23 2023-01-03T11:54:35 2022-08-02 2022-05-19T18:35:36 30.194.6.115 veniam@Thoughtstorm.mil Basil Street 79 +-2147336695 false 42 -7202 27919 1898713395 1177326785 -302.0104 -1.268944460183375E9 61604656210729534.717 6683002058708470.832 2022-08-20 2022-08-14T01:41:12 2022-11-02 2022-05-15T04:22:07 36.86.77.214 delectus_maiores_fugit@Rhyzio.org Briar Crest Crossing 37 +-2147330925 false -122 -21211 -2331 1906695924 -1342280417 5545.3013 -1.286038914681617E9 31911132334645267.930 84364209624711210.131 2022-02-16 2022-03-11T12:05:33 2022-11-24 2022-12-17T19:56:16 6.87.14.74 rCampbell@Riffpath.com Forest Run Terrace 13 + +-- !sql -- +-2145739104 true 10 -22603 6132 -984517723 138439036 8683.904 1.681202635040786E9 49683339998558535.395 38251259739648714.297 2022-04-26 2022-09-12T00:32:18 2022-11-20 2023-01-09T16:19:06 180.215.212.86 KathyRoberts@Talane.info Darwin Center 26 +-2140012242 false 10 30893 -16192 -175522451 -1382546546 21324.643 2.017216342012696E9 41477187479096470.647 25445001389089818.791 2022-11-06 2022-09-02T12:04:05 2022-05-29 2022-02-04T22:21:46 24.25.69.81 nam_quasi@Photospace.mil Jay Way 9 +-2130269306 false 10 30342 -18732 1461226453 -1257020753 -10751.815 3.44246067782915E8 2456538047280540.838 37394928326629689.946 2022-11-28 2022-05-04T20:40:19 2022-08-25 2022-03-18T10:17:35 179.198.200.96 eFuller@Skynoodle.com Tennyson Street 83 +-2122709724 true 10 -8985 -30620 -1375603501 631094037 14711.055 -1.210030062083139E9 96220820029888063.156 42161382030214480.728 2022-05-28 2023-01-03T20:44:27 2022-06-11 2022-07-26T22:49:22 13.249.135.222 uDixon@Shufflebeat.name Riverside Parkway 72 +-2117749737 false 10 26335 30644 1841596444 283308539 18848.148 3.5339747538014E8 11924963560520504.166 28287350935413049.601 2022-08-01 2022-04-21T02:28:54 2022-02-27 2022-09-02T17:11:17 183.108.102.1 pHanson@Cogibox.com Maple Wood Street 40 +-2113239713 false 10 27624 31311 711781944 -1838033894 -12299.482 -1.88263132184351E9 9480201396831049.605 52114965946122870.302 2022-06-11 2022-08-31T08:54:30 2022-03-26 2023-01-08T23:28:27 200.161.156.176 et@Buzzster.net Westport Drive 82 +-2107773486 false 10 27096 10368 1579374450 1370327646 -15339.031 2.110010890135424E9 54514853031265543.378 38546969634312019.180 2022-12-31 2022-10-07T10:18:27 2022-10-01 2022-07-09T11:41:11 121.120.227.53 JuliaDean@Plambee.com Sugar Crossing 43 +-2107242025 true 10 25215 26566 1292568651 -2126795906 11912.074 -2.140044503516609E9 98695561934257164.368 18845397264645075.775 2022-05-21 2022-09-24T23:00:21 2022-02-12 2022-11-24T19:17:03 141.226.90.50 AnnaGonzalez@Eimbee.mil Cody Street 78 +-2106969609 true 10 29572 16738 1736115820 -957295886 -13319.206 -1.333603562816737E9 91224478600376111.942 69457425159617037.453 2022-09-06 2022-05-08T19:52:36 2022-04-05 2022-08-17T19:23:31 222.79.139.99 WalterFox@Voomm.net Oxford Alley 77 +-2102307005 true 10 -23674 24613 -1810828490 -47095409 -14686.167 2.072108685694799E9 39847820962230526.125 584354832299375.156 2022-03-27 2022-02-11T13:46:06 2022-12-25 2022-11-28T09:37:49 213.146.33.250 JuliaSimmons@Zazio.info Eagle Crest Terrace 84 + +-- !sql -- +tbl_scalar_types_dup DUP_KEYS k1 BIGINT BIGINT Yes true \N true + c_bool BOOLEAN BOOLEAN Yes false \N NONE true + c_tinyint TINYINT TINYINT Yes false \N NONE true + c_smallint SMALLINT SMALLINT Yes false \N NONE true + c_int BIGINT BIGINT Yes false \N NONE true + c_bigint BIGINT BIGINT Yes false \N NONE true + c_largeint LARGEINT LARGEINT Yes false \N NONE true + c_float FLOAT FLOAT Yes false \N NONE true + c_double DOUBLE DOUBLE Yes false \N NONE true + c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true + c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true + c_date DATE DATEV2 Yes false \N NONE true + c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true + c_datev2 DATE DATEV2 Yes false \N NONE true + c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true + c_char CHAR(15) CHAR(15) Yes false \N NONE true + c_varchar VARCHAR(100) VARCHAR(100) Yes false \N NONE true + c_string TEXT TEXT Yes false \N NONE true + +mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N true `c_tinyint` + mv_c_bool BOOLEAN BOOLEAN Yes true \N true `c_bool` + mv_k1 BIGINT BIGINT Yes true \N true `k1` + mv_c_smallint SMALLINT SMALLINT Yes false \N NONE true `c_smallint` + mv_c_int BIGINT BIGINT Yes false \N NONE true `c_int` + mv_c_bigint BIGINT BIGINT Yes false \N NONE true `c_bigint` + mv_c_largeint LARGEINT LARGEINT Yes false \N NONE true `c_largeint` + mv_c_float FLOAT FLOAT Yes false \N NONE true `c_float` + mv_c_double DOUBLE DOUBLE Yes false \N NONE true `c_double` + mv_c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimal` + mv_c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimalv3` + mv_c_date DATE DATEV2 Yes false \N NONE true `c_date` + mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` + mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` + mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` + mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` + mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` + mv_c_string TEXT TEXT Yes false \N NONE true `c_string` + diff --git a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy new file mode 100644 index 00000000000000..9f06f049ce64d6 --- /dev/null +++ b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy @@ -0,0 +1,101 @@ +// 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("test_create_table_like_nereids") { + sql "SET enable_nereids_planner=true;" + sql "SET enable_fallback_to_original_planner=false;" + sql "set disable_nereids_rules=PRUNE_EMPTY_PARTITION" + + + sql "drop table if exists mal_test_create_table_like" + sql """create table mal_test_create_table_like(pk int, a int, b int) distributed by hash(pk) buckets 10 + properties('replication_num' = '1');""" + sql """insert into mal_test_create_table_like values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) + ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" + sql "sync" + sql "alter table mal_test_create_table_like add rollup ru1(a,pk);" + sleep(2000) + sql "alter table mal_test_create_table_like add rollup ru2(b,pk);" + sleep(2000) + + // no rollup + sql "drop table if exists table_like" + sql "CREATE TABLE table_like LIKE mal_test_create_table_like;" + sql """insert into table_like values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) + ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" + "sync" + qt_test_without_roll_up "select * from table_like order by pk,a,b;" + + // with all rollup + sql "drop table if exists table_like_with_roll_up" + sql "CREATE TABLE table_like_with_roll_up LIKE mal_test_create_table_like with rollup;" + explain { + sql ("select sum(a) from table_like_with_roll_up group by a") + contains "ru1" + } ; + explain { + sql ("select sum(b) from table_like_with_roll_up group by b,pk ;") + contains "ru2" + } ; + + // with partial rollup + sql "drop table if exists table_like_with_partial_roll_up;" + sql "CREATE TABLE table_like_with_partial_roll_up LIKE mal_test_create_table_like with rollup (ru1);" + sql "select * from table_like_with_partial_roll_up order by pk, a, b" + explain { + sql("select sum(a) from table_like_with_partial_roll_up group by a") + contains("ru1") + } ; + explain { + sql ("select sum(b) from table_like_with_partial_roll_up group by b,pk ;") + notContains "ru2" + } ; + sql """insert into table_like_with_partial_roll_up values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) + ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" + sql "sync" + sleep(2000) + sql "select sum(a) from table_like_with_partial_roll_up group by a order by 1" + + // test if not exists + sql "drop table if exists table_like_with_partial_roll_up_exists" + sql """CREATE TABLE if not exists table_like_with_partial_roll_up_exists + LIKE mal_test_create_table_like with rollup (ru1);""" + + sql "drop table if exists test_create_table_like_char_255" + sql """ + CREATE TABLE test_create_table_like_char_255 + ( + `id` INT NOT NULL, + `name` CHAR(255) + ) + UNIQUE KEY(`id`) + DISTRIBUTED BY HASH(`id`) BUCKETS AUTO + PROPERTIES ( + "replication_num" = "1", + "light_schema_change" = "true" + ); + """ + sql "drop table if exists new_char_255" + qt_test_char_255 """ + create table new_char_255 like test_create_table_like_char_255; + """ + def res1 = sql "show create table new_char_255" + mustContain(res1[0][1], "CHARACTER(255)") + + sql "insert into new_char_255 values(123,'abcdddddd')" + qt_select "select * from new_char_255" +} \ No newline at end of file From d1765b5bcedde956017389ff956b340593ae0c9f Mon Sep 17 00:00:00 2001 From: moailing Date: Thu, 11 Jul 2024 18:07:25 +0800 Subject: [PATCH 2/4] [Fix](planner) fix bug of char(255) toSql (#37340) --- .../java/org/apache/doris/catalog/CreateFunctionTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java index 4781a7e6a668a7..6b97d863179fba 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java @@ -285,12 +285,9 @@ public void testCreateGlobalFunction() throws Exception { testFunctionQuery(ctx, queryStr, true); queryStr = "select to_char(k1, 4) from db2.tbl1;"; -<<<<<<< HEAD - Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("CAST(`k1` AS CHARACTER)")); -======= + Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), "CAST(`k1` AS CHARACTER(255))")); ->>>>>>> a317eba747 ([Fix](planner) fix bug of char(255) toSql (#37340)) } private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception { From 0dcc2783d715b1a4a0452772bb739bc4d07fc3c9 Mon Sep 17 00:00:00 2001 From: moailing Date: Thu, 11 Jul 2024 18:13:51 +0800 Subject: [PATCH 3/4] [Fix](planner) fix bug of char(255) toSql (#37340) --- .../java/org/apache/doris/catalog/CreateFunctionTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java index 6b97d863179fba..76f54eea9f63ad 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/CreateFunctionTest.java @@ -285,9 +285,7 @@ public void testCreateGlobalFunction() throws Exception { testFunctionQuery(ctx, queryStr, true); queryStr = "select to_char(k1, 4) from db2.tbl1;"; - - Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(), - "CAST(`k1` AS CHARACTER(255))")); + Assert.assertTrue(dorisAssert.query(queryStr).explainQuery().contains("CAST(`k1` AS CHARACTER(255))")); } private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception { From 3c1e7f8a00cffdf5b203419681a0b020449accea Mon Sep 17 00:00:00 2001 From: moailing Date: Thu, 11 Jul 2024 19:21:52 +0800 Subject: [PATCH 4/4] [Fix](planner) fix bug of char(255) toSql (#37340) --- .../ddl_p0/test_create_table_like_nereids.out | 26 ----- .../schema_change_modify_mv_column_type.out | 103 ------------------ .../test_create_table_like_nereids.groovy | 101 ----------------- 3 files changed, 230 deletions(-) delete mode 100644 regression-test/data/ddl_p0/test_create_table_like_nereids.out delete mode 100644 regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out delete mode 100644 regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy diff --git a/regression-test/data/ddl_p0/test_create_table_like_nereids.out b/regression-test/data/ddl_p0/test_create_table_like_nereids.out deleted file mode 100644 index 137a4aa9466b4e..00000000000000 --- a/regression-test/data/ddl_p0/test_create_table_like_nereids.out +++ /dev/null @@ -1,26 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !test_without_roll_up -- -1 1 2 -1 1 4 -1 3 6 -2 1 3 -2 1 4 -2 1 7 -2 3 5 -2 3 9 -2 4 2 -3 2 8 -3 5 \N -3 5 6 -3 5 6 -3 5 8 -4 5 6 -6 \N 6 -6 7 1 - --- !test_char_255 -- -0 - --- !select -- -123 abcdddddd - diff --git a/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out b/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out deleted file mode 100644 index 1cf151dc70c8bf..00000000000000 --- a/regression-test/data/schema_change_p0/modify_col_type_dup/schema_change_modify_mv_column_type.out +++ /dev/null @@ -1,103 +0,0 @@ --- This file is automatically generated. You should know what you did if you want to edit this --- !sql -- -tbl_scalar_types_dup DUP_KEYS k1 BIGINT BIGINT Yes true \N true - c_bool BOOLEAN BOOLEAN Yes false \N NONE true - c_tinyint TINYINT TINYINT Yes false \N NONE true - c_smallint SMALLINT SMALLINT Yes false \N NONE true - c_int INT INT Yes false \N NONE true - c_bigint BIGINT BIGINT Yes false \N NONE true - c_largeint LARGEINT LARGEINT Yes false \N NONE true - c_float FLOAT FLOAT Yes false \N NONE true - c_double DOUBLE DOUBLE Yes false \N NONE true - c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true - c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true - c_date DATE DATEV2 Yes false \N NONE true - c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true - c_datev2 DATE DATEV2 Yes false \N NONE true - c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true - c_char CHAR(15) CHAR(15) Yes false \N NONE true - c_varchar VARCHAR(100) VARCHAR(100) Yes false \N NONE true - c_string TEXT TEXT Yes false \N NONE true - -mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N true `c_tinyint` - mv_c_bool BOOLEAN BOOLEAN Yes true \N true `c_bool` - mv_k1 BIGINT BIGINT Yes true \N true `k1` - mv_c_smallint SMALLINT SMALLINT Yes false \N NONE true `c_smallint` - mv_c_int INT INT Yes false \N NONE true `c_int` - mv_c_bigint BIGINT BIGINT Yes false \N NONE true `c_bigint` - mv_c_largeint LARGEINT LARGEINT Yes false \N NONE true `c_largeint` - mv_c_float FLOAT FLOAT Yes false \N NONE true `c_float` - mv_c_double DOUBLE DOUBLE Yes false \N NONE true `c_double` - mv_c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimal` - mv_c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimalv3` - mv_c_date DATE DATEV2 Yes false \N NONE true `c_date` - mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` - mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` - mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` - mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` - mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` - mv_c_string TEXT TEXT Yes false \N NONE true `c_string` - --- !sql -- --2147475406 true 45 23794 -11023 915989078 2115356192 15927.068 1.392557423391501E9 45951348783208518.810 8340516346665031.310 2022-01-26 2022-04-13T11:13:48 2022-01-31 2022-02-16T06:07:21 130.50.6.0 DeniseMatthews@Yozio.mil Londonderry Alley 61 --2147424303 false -28 -5177 -1409 149417728 553396597 -10123.558 -1.268722910924068E9 67354830622005524.848 52407243294991364.348 2022-06-29 2022-05-06T09:30:02 2023-01-09 2022-03-12T14:26 109.50.92.119 CraigHughes@Talane.biz Heath Drive 38 --2147413967 true -75 30533 -5435 -727385447 32929830 9577.564 1.334766997510087E9 39973144022098028.800 5886463393340733.108 2022-06-23 2022-05-10T19:13:50 2022-01-17 2022-11-26T22:49:36 157.38.90.25 JoshuaLewis@Jayo.mil Loeprich Crossing 43 --2147380173 true -79 -5785 9752 1851350218 1121852298 25652.402 -1.618061059513558E9 95821873014545736.897 38923569966532828.626 2022-10-30 2022-05-02T17:06:33 2022-08-11 2022-02-08T10:19:47 217.198.98.239 JoseBoyd@Voonder.info Lawn Lane 78 --2147374459 false -118 -30267 -14606 262497842 -1811881704 8211.805 2.37851933046663E8 37354136531251060.755 63024710145324035.720 2022-10-11 2022-01-17T10:20:18 2022-04-12 2022-10-24T18:14:38 16.243.195.81 BrendaBoyd@Talane.net Annamark Pass 72 --2147369329 false -121 -22859 4733 -378861997 385323541 -22969.846 1.483825622420542E9 50940877800950041.950 87108729227937387.294 2022-06-05 2022-08-18T05:39:56 2022-08-21 2022-12-12T08:43:59 16.27.107.167 PhyllisSmith@Zoombox.org Village Green Terrace 55 --2147367329 true 84 21471 -29331 1823545950 1200800855 -13832.219 8.01505090724918E8 45495296019797580.477 45196001436348967.557 2022-02-17 2022-05-23T01:44:31 2022-08-01 2022-08-16T10:32:36 84.110.209.128 vLane@Dablist.edu Packers Street 34 --2147339287 true 62 28989 -32018 650184880 -365849435 -21644.414 -7.8648426469503E7 92593387160450273.870 39588697152489527.185 2022-07-23 2023-01-03T11:54:35 2022-08-02 2022-05-19T18:35:36 30.194.6.115 veniam@Thoughtstorm.mil Basil Street 79 --2147336695 false 42 -7202 27919 1898713395 1177326785 -302.0104 -1.268944460183375E9 61604656210729534.717 6683002058708470.832 2022-08-20 2022-08-14T01:41:12 2022-11-02 2022-05-15T04:22:07 36.86.77.214 delectus_maiores_fugit@Rhyzio.org Briar Crest Crossing 37 --2147330925 false -122 -21211 -2331 1906695924 -1342280417 5545.3013 -1.286038914681617E9 31911132334645267.930 84364209624711210.131 2022-02-16 2022-03-11T12:05:33 2022-11-24 2022-12-17T19:56:16 6.87.14.74 rCampbell@Riffpath.com Forest Run Terrace 13 - --- !sql -- --2145739104 true 10 -22603 6132 -984517723 138439036 8683.904 1.681202635040786E9 49683339998558535.395 38251259739648714.297 2022-04-26 2022-09-12T00:32:18 2022-11-20 2023-01-09T16:19:06 180.215.212.86 KathyRoberts@Talane.info Darwin Center 26 --2140012242 false 10 30893 -16192 -175522451 -1382546546 21324.643 2.017216342012696E9 41477187479096470.647 25445001389089818.791 2022-11-06 2022-09-02T12:04:05 2022-05-29 2022-02-04T22:21:46 24.25.69.81 nam_quasi@Photospace.mil Jay Way 9 --2130269306 false 10 30342 -18732 1461226453 -1257020753 -10751.815 3.44246067782915E8 2456538047280540.838 37394928326629689.946 2022-11-28 2022-05-04T20:40:19 2022-08-25 2022-03-18T10:17:35 179.198.200.96 eFuller@Skynoodle.com Tennyson Street 83 --2122709724 true 10 -8985 -30620 -1375603501 631094037 14711.055 -1.210030062083139E9 96220820029888063.156 42161382030214480.728 2022-05-28 2023-01-03T20:44:27 2022-06-11 2022-07-26T22:49:22 13.249.135.222 uDixon@Shufflebeat.name Riverside Parkway 72 --2117749737 false 10 26335 30644 1841596444 283308539 18848.148 3.5339747538014E8 11924963560520504.166 28287350935413049.601 2022-08-01 2022-04-21T02:28:54 2022-02-27 2022-09-02T17:11:17 183.108.102.1 pHanson@Cogibox.com Maple Wood Street 40 --2113239713 false 10 27624 31311 711781944 -1838033894 -12299.482 -1.88263132184351E9 9480201396831049.605 52114965946122870.302 2022-06-11 2022-08-31T08:54:30 2022-03-26 2023-01-08T23:28:27 200.161.156.176 et@Buzzster.net Westport Drive 82 --2107773486 false 10 27096 10368 1579374450 1370327646 -15339.031 2.110010890135424E9 54514853031265543.378 38546969634312019.180 2022-12-31 2022-10-07T10:18:27 2022-10-01 2022-07-09T11:41:11 121.120.227.53 JuliaDean@Plambee.com Sugar Crossing 43 --2107242025 true 10 25215 26566 1292568651 -2126795906 11912.074 -2.140044503516609E9 98695561934257164.368 18845397264645075.775 2022-05-21 2022-09-24T23:00:21 2022-02-12 2022-11-24T19:17:03 141.226.90.50 AnnaGonzalez@Eimbee.mil Cody Street 78 --2106969609 true 10 29572 16738 1736115820 -957295886 -13319.206 -1.333603562816737E9 91224478600376111.942 69457425159617037.453 2022-09-06 2022-05-08T19:52:36 2022-04-05 2022-08-17T19:23:31 222.79.139.99 WalterFox@Voomm.net Oxford Alley 77 --2102307005 true 10 -23674 24613 -1810828490 -47095409 -14686.167 2.072108685694799E9 39847820962230526.125 584354832299375.156 2022-03-27 2022-02-11T13:46:06 2022-12-25 2022-11-28T09:37:49 213.146.33.250 JuliaSimmons@Zazio.info Eagle Crest Terrace 84 - --- !sql -- -tbl_scalar_types_dup DUP_KEYS k1 BIGINT BIGINT Yes true \N true - c_bool BOOLEAN BOOLEAN Yes false \N NONE true - c_tinyint TINYINT TINYINT Yes false \N NONE true - c_smallint SMALLINT SMALLINT Yes false \N NONE true - c_int BIGINT BIGINT Yes false \N NONE true - c_bigint BIGINT BIGINT Yes false \N NONE true - c_largeint LARGEINT LARGEINT Yes false \N NONE true - c_float FLOAT FLOAT Yes false \N NONE true - c_double DOUBLE DOUBLE Yes false \N NONE true - c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true - c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true - c_date DATE DATEV2 Yes false \N NONE true - c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true - c_datev2 DATE DATEV2 Yes false \N NONE true - c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true - c_char CHAR(15) CHAR(15) Yes false \N NONE true - c_varchar VARCHAR(100) VARCHAR(100) Yes false \N NONE true - c_string TEXT TEXT Yes false \N NONE true - -mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N true `c_tinyint` - mv_c_bool BOOLEAN BOOLEAN Yes true \N true `c_bool` - mv_k1 BIGINT BIGINT Yes true \N true `k1` - mv_c_smallint SMALLINT SMALLINT Yes false \N NONE true `c_smallint` - mv_c_int BIGINT BIGINT Yes false \N NONE true `c_int` - mv_c_bigint BIGINT BIGINT Yes false \N NONE true `c_bigint` - mv_c_largeint LARGEINT LARGEINT Yes false \N NONE true `c_largeint` - mv_c_float FLOAT FLOAT Yes false \N NONE true `c_float` - mv_c_double DOUBLE DOUBLE Yes false \N NONE true `c_double` - mv_c_decimal DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimal` - mv_c_decimalv3 DECIMAL(20, 3) DECIMALV3(20, 3) Yes false \N NONE true `c_decimalv3` - mv_c_date DATE DATEV2 Yes false \N NONE true `c_date` - mv_c_datetime DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetime` - mv_c_datev2 DATE DATEV2 Yes false \N NONE true `c_datev2` - mv_c_datetimev2 DATETIME DATETIMEV2(0) Yes false \N NONE true `c_datetimev2` - mv_c_char CHARACTER(255) CHARACTER(255) Yes false \N NONE true `c_char` - mv_c_varchar VARCHAR(65533) VARCHAR(65533) Yes false \N NONE true `c_varchar` - mv_c_string TEXT TEXT Yes false \N NONE true `c_string` - diff --git a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy deleted file mode 100644 index 9f06f049ce64d6..00000000000000 --- a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy +++ /dev/null @@ -1,101 +0,0 @@ -// 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("test_create_table_like_nereids") { - sql "SET enable_nereids_planner=true;" - sql "SET enable_fallback_to_original_planner=false;" - sql "set disable_nereids_rules=PRUNE_EMPTY_PARTITION" - - - sql "drop table if exists mal_test_create_table_like" - sql """create table mal_test_create_table_like(pk int, a int, b int) distributed by hash(pk) buckets 10 - properties('replication_num' = '1');""" - sql """insert into mal_test_create_table_like values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) - ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" - sql "sync" - sql "alter table mal_test_create_table_like add rollup ru1(a,pk);" - sleep(2000) - sql "alter table mal_test_create_table_like add rollup ru2(b,pk);" - sleep(2000) - - // no rollup - sql "drop table if exists table_like" - sql "CREATE TABLE table_like LIKE mal_test_create_table_like;" - sql """insert into table_like values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) - ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" - "sync" - qt_test_without_roll_up "select * from table_like order by pk,a,b;" - - // with all rollup - sql "drop table if exists table_like_with_roll_up" - sql "CREATE TABLE table_like_with_roll_up LIKE mal_test_create_table_like with rollup;" - explain { - sql ("select sum(a) from table_like_with_roll_up group by a") - contains "ru1" - } ; - explain { - sql ("select sum(b) from table_like_with_roll_up group by b,pk ;") - contains "ru2" - } ; - - // with partial rollup - sql "drop table if exists table_like_with_partial_roll_up;" - sql "CREATE TABLE table_like_with_partial_roll_up LIKE mal_test_create_table_like with rollup (ru1);" - sql "select * from table_like_with_partial_roll_up order by pk, a, b" - explain { - sql("select sum(a) from table_like_with_partial_roll_up group by a") - contains("ru1") - } ; - explain { - sql ("select sum(b) from table_like_with_partial_roll_up group by b,pk ;") - notContains "ru2" - } ; - sql """insert into table_like_with_partial_roll_up values(2,1,3),(1,1,2),(3,5,6),(6,null,6),(4,5,6),(2,1,4),(2,3,5),(1,1,4) - ,(3,5,6),(3,5,null),(6,7,1),(2,1,7),(2,4,2),(2,3,9),(1,3,6),(3,5,8),(3,2,8);""" - sql "sync" - sleep(2000) - sql "select sum(a) from table_like_with_partial_roll_up group by a order by 1" - - // test if not exists - sql "drop table if exists table_like_with_partial_roll_up_exists" - sql """CREATE TABLE if not exists table_like_with_partial_roll_up_exists - LIKE mal_test_create_table_like with rollup (ru1);""" - - sql "drop table if exists test_create_table_like_char_255" - sql """ - CREATE TABLE test_create_table_like_char_255 - ( - `id` INT NOT NULL, - `name` CHAR(255) - ) - UNIQUE KEY(`id`) - DISTRIBUTED BY HASH(`id`) BUCKETS AUTO - PROPERTIES ( - "replication_num" = "1", - "light_schema_change" = "true" - ); - """ - sql "drop table if exists new_char_255" - qt_test_char_255 """ - create table new_char_255 like test_create_table_like_char_255; - """ - def res1 = sql "show create table new_char_255" - mustContain(res1[0][1], "CHARACTER(255)") - - sql "insert into new_char_255 values(123,'abcdddddd')" - qt_select "select * from new_char_255" -} \ No newline at end of file