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 bug of char(255) toSql #37340

Merged
merged 2 commits into from
Jul 11, 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 @@ -579,7 +579,7 @@ public static ScalarType createHllType() {
public String toString() {
if (type == PrimitiveType.CHAR) {
if (isWildcardChar()) {
return "CHARACTER";
return "CHARACTER(" + MAX_CHAR_LENGTH + ")";
morrySnow marked this conversation as resolved.
Show resolved Hide resolved
}
return "CHAR(" + len + ")";
} else if (type == PrimitiveType.DECIMALV2) {
Expand Down Expand Up @@ -617,7 +617,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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ public void testCreateGlobalFunction() throws Exception {

queryStr = "select to_char(k1, 4) from db2.tbl1;";
Assert.assertTrue(containsIgnoreCase(dorisAssert.query(queryStr).explainQuery(),
"CAST(`k1` AS CHARACTER)"));
"CAST(`k1` AS CHARACTER(255))"));
}

private void testFunctionQuery(ConnectContext ctx, String queryStr, Boolean isStringLiteral) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@
6 \N 6
6 7 1

-- !test_char_255 --
0

-- !select --
123 abcdddddd

Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N tru
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 CHARACTER Yes false \N NONE true `c_char`
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`

Expand Down Expand Up @@ -97,7 +97,7 @@ mv_tbl_scalar_types_dup_1 DUP_KEYS mv_c_tinyint TINYINT TINYINT Yes true \N tru
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 CHARACTER Yes false \N NONE true `c_char`
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`

Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,28 @@ suite("test_create_table_like_nereids") {
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"
}
Loading