This is an automated email from the ASF dual-hosted git repository.
morrysnow pushed a commit to branch branch-2.1
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push:
new 6214d6421f1 [Fix](planner) fix bug of char(255) toSql (#37340) (#37671)
6214d6421f1 is described below
commit 6214d6421f1e2706d7ee4f76db13749b4fb995c3
Author: feiniaofeiafei <[email protected]>
AuthorDate: Fri Jul 12 10:33:24 2024 +0800
[Fix](planner) fix bug of char(255) toSql (#37340) (#37671)
cherry-pick #37340 from master
---
.../java/org/apache/doris/catalog/ScalarType.java | 4 +--
.../apache/doris/catalog/CreateFunctionTest.java | 2 +-
.../data/ddl_p0/test_create_table_like_nereids.out | 6 +++++
.../schema_change_modify_mv_column_type.out | 4 +--
.../plugins/plugin_must_contains.groovy | 30 ++++++++++++++++++++++
.../ddl_p0/test_create_table_like_nereids.groovy | 24 +++++++++++++++++
6 files changed, 65 insertions(+), 5 deletions(-)
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 4b4155c3d77..cf57b45b3d1 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
@@ -579,7 +579,7 @@ public class ScalarType extends Type {
public String toString() {
if (type == PrimitiveType.CHAR) {
if (isWildcardChar()) {
- return "CHARACTER";
+ return "CHARACTER(" + MAX_CHAR_LENGTH + ")";
}
return "CHAR(" + len + ")";
} else if (type == PrimitiveType.DECIMALV2) {
@@ -617,7 +617,7 @@ public class ScalarType extends Type {
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 c342d858fe1..6646c356a8f 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
@@ -295,7 +295,7 @@ public class CreateFunctionTest {
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 {
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
index 4ecbecb1505..137a4aa9466 100644
--- a/regression-test/data/ddl_p0/test_create_table_like_nereids.out
+++ b/regression-test/data/ddl_p0/test_create_table_like_nereids.out
@@ -18,3 +18,9 @@
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
index 4e6f3c7a5eb..1cf151dc70c 100644
---
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
@@ -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`
@@ -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`
diff --git a/regression-test/plugins/plugin_must_contains.groovy
b/regression-test/plugins/plugin_must_contains.groovy
new file mode 100644
index 00000000000..fc138372f2a
--- /dev/null
+++ b/regression-test/plugins/plugin_must_contains.groovy
@@ -0,0 +1,30 @@
+// 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.
+
+import org.apache.doris.regression.suite.Suite
+
+Suite.metaClass.mustContain = {String str1, String str2 ->
+ try {
+ assert str1.contains(str2)
+ logger.info("Assertion passed: '${str1}' contains '${str2}'")
+ } catch (AssertionError e) {
+ logger.error("Assertion failed: '${str1}' does not contain '${str2}'")
+ throw e
+ }
+ return true
+}
+logger.info("Added 'mustContain' function to Suite")
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
index d9d59b50ed5..9f06f049ce6 100644
--- a/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy
+++ b/regression-test/suites/ddl_p0/test_create_table_like_nereids.groovy
@@ -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"
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]