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

[opt](ctas) add a variable to control varchar length in ctas (#37069) #37284

Merged
merged 1 commit into from
Jul 4, 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 @@ -143,10 +143,12 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
}
}
} 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,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,
Expand Down Expand Up @@ -1902,6 +1904,13 @@ public void setIgnoreShapePlanNodes(String ignoreShapePlanNodes) {
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;
}
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/nereids_p0/create_table/test_ctas.out
Original file line number Diff line number Diff line change
Expand Up @@ -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

12 changes: 8 additions & 4 deletions regression-test/suites/nereids_p0/create_table/test_ctas.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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 """
Expand Down Expand Up @@ -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"""

}

Loading