This is an automated email from the ASF dual-hosted git repository. morrysnow 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 2e63fefabd4 [opt](ctas) add a variable to control varchar length in ctas (#37069) 2e63fefabd4 is described below commit 2e63fefabd4a4a732cfac10187c274d3d3a42b12 Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Tue Jul 2 16:20:01 2024 +0800 [opt](ctas) add a variable to control varchar length in ctas (#37069) add a new session variable: use_max_length_of_varchar_in_ctas In CTAS (Create Table As Select), if CHAR/VARCHAR columns do not originate from the source table, whether to set the length of such a column to MAX, which is 65533. The default is true. --- .../nereids/trees/plans/commands/CreateTableCommand.java | 10 ++++++---- .../src/main/java/org/apache/doris/qe/SessionVariable.java | 9 +++++++++ regression-test/data/nereids_p0/create_table/test_ctas.out | 3 +++ .../suites/nereids_p0/create_table/test_ctas.groovy | 12 ++++++++---- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java index 7df93d8b9a9..f2dd92fe328 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableCommand.java @@ -143,10 +143,12 @@ public class CreateTableCommand extends Command implements ForwardWithSync { } } } else { - dataType = TypeCoercionUtils.replaceSpecifiedType(dataType, - VarcharType.class, VarcharType.MAX_VARCHAR_TYPE); - dataType = TypeCoercionUtils.replaceSpecifiedType(dataType, - CharType.class, VarcharType.MAX_VARCHAR_TYPE); + if (ctx.getSessionVariable().useMaxLengthOfVarcharInCtas) { + dataType = TypeCoercionUtils.replaceSpecifiedType(dataType, + VarcharType.class, VarcharType.MAX_VARCHAR_TYPE); + dataType = TypeCoercionUtils.replaceSpecifiedType(dataType, + CharType.class, VarcharType.MAX_VARCHAR_TYPE); + } } } // if the column is an expression, we set it to nullable, otherwise according to the nullable of the slot. diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java index 59b5d89ac2b..29d3fbf985b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/SessionVariable.java @@ -603,6 +603,8 @@ public class SessionVariable implements Serializable, Writable { public static final String MAX_COLUMN_READER_NUM = "max_column_reader_num"; + public static final String USE_MAX_LENGTH_OF_VARCHAR_IN_CTAS = "use_max_length_of_varchar_in_ctas"; + public static final List<String> DEBUG_VARIABLES = ImmutableList.of( SKIP_DELETE_PREDICATE, SKIP_DELETE_BITMAP, @@ -1985,6 +1987,13 @@ public class SessionVariable implements Serializable, Writable { checker = "checkExternalAggPartitionBits", fuzzy = true) public int externalAggPartitionBits = 5; // means that the hash table will be partitioned into 32 blocks. + @VariableMgr.VarAttr(name = USE_MAX_LENGTH_OF_VARCHAR_IN_CTAS, description = { + "在CTAS中,如果 CHAR / VARCHAR 列不来自于源表,是否是将这一列的长度设置为 MAX,即65533。默认为 true。", + "In CTAS (Create Table As Select), if CHAR/VARCHAR columns do not originate from the source table," + + " whether to set the length of such a column to MAX, which is 65533. The default is true." + }) + public boolean useMaxLengthOfVarcharInCtas = true; + public boolean isEnableJoinSpill() { return enableJoinSpill; } diff --git a/regression-test/data/nereids_p0/create_table/test_ctas.out b/regression-test/data/nereids_p0/create_table/test_ctas.out index 447d405ad31..976a2ead90b 100644 --- a/regression-test/data/nereids_p0/create_table/test_ctas.out +++ b/regression-test/data/nereids_p0/create_table/test_ctas.out @@ -21,3 +21,6 @@ r2 {"title":"Amount","value":2.1} 2.1 2.20000 2.3 2.400000 2.500000 2.600000 2.1 2.20000 2.3 2.400000 2.500000 2.600000 +-- !desc -- +__substring_0 VARCHAR(30) Yes true \N + diff --git a/regression-test/suites/nereids_p0/create_table/test_ctas.groovy b/regression-test/suites/nereids_p0/create_table/test_ctas.groovy index e6cc58fdba1..d415291d1ef 100644 --- a/regression-test/suites/nereids_p0/create_table/test_ctas.groovy +++ b/regression-test/suites/nereids_p0/create_table/test_ctas.groovy @@ -16,10 +16,6 @@ // under the License. suite("nereids_test_ctas") { - sql 'set enable_nereids_planner=true' - sql 'set enable_fallback_to_original_planner=false' - sql 'set enable_nereids_dml=true' - sql """ DROP TABLE IF EXISTS test_ctas """ sql """ DROP TABLE IF EXISTS test_ctas1 """ sql """ DROP TABLE IF EXISTS test_ctas2 """ @@ -271,5 +267,13 @@ suite("nereids_test_ctas") { sql 'drop table c' sql 'drop table test_date_v2' } + + sql """DROP TABLE IF EXISTS test_varchar_length""" + sql """set use_max_length_of_varchar_in_ctas = false""" + sql """CREATE TABLE test_varchar_length properties ("replication_num"="1") AS SELECT CAST("1" AS VARCHAR(30))""" + qt_desc """desc test_varchar_length""" + sql """DROP TABLE IF EXISTS test_varchar_length""" + sql """set use_max_length_of_varchar_in_ctas = true""" + } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org