This is an automated email from the ASF dual-hosted git repository.
morningman 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 572f491756 [fix](ctas) text column type len = 1 when create table as
select (#13906)
572f491756 is described below
commit 572f49175666fb71dbe040c5cff60252398775be
Author: xueweizhang <[email protected]>
AuthorDate: Wed Nov 9 09:09:34 2022 +0800
[fix](ctas) text column type len = 1 when create table as select (#13906)
Signed-off-by: nextdreamblue <[email protected]>
---
.../java/org/apache/doris/analysis/ColumnDef.java | 7 ++++++-
.../org/apache/doris/datasource/InternalCatalog.java | 3 ++-
regression-test/data/ddl_p0/test_ctas.out | 8 +++++++-
regression-test/suites/ddl_p0/test_ctas.groovy | 19 ++++++++++++++++++-
4 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
index d6b7981993..170ceaea4c 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java
@@ -206,7 +206,12 @@ public class ColumnDef {
if (typeDef.getType().isScalarType()) {
final ScalarType targetType = (ScalarType) typeDef.getType();
if (targetType.getPrimitiveType().isStringType() &&
!targetType.isLengthSet()) {
- targetType.setLength(1);
+ if (targetType.getPrimitiveType() != PrimitiveType.STRING) {
+ targetType.setLength(1);
+ } else {
+ // alway set text length MAX_STRING_LENGTH
+ targetType.setLength(ScalarType.MAX_STRING_LENGTH);
+ }
}
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
index c66ee75e46..6bfec923e2 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java
@@ -1206,7 +1206,8 @@ public class InternalCatalog implements
CatalogIf<Database> {
Expr resultExpr = resultExprs.get(i);
Type resultType = resultExpr.getType();
if (resultType.isStringType() && resultType.getLength() < 0) {
- typeDef = new TypeDef(Type.STRING);
+ // alway set text length MAX_STRING_LENGTH
+ typeDef = new TypeDef(ScalarType.createStringType());
} else if (resultType.isDecimalV2() &&
resultType.equals(ScalarType.DECIMALV2)) {
typeDef = new TypeDef(ScalarType.createDecimalType(27, 9));
} else if (resultType.isDecimalV3()) {
diff --git a/regression-test/data/ddl_p0/test_ctas.out
b/regression-test/data/ddl_p0/test_ctas.out
index aa41c6a791..2a8f9f7979 100644
--- a/regression-test/data/ddl_p0/test_ctas.out
+++ b/regression-test/data/ddl_p0/test_ctas.out
@@ -1,6 +1,12 @@
-- This file is automatically generated. You should know what you did if you
want to edit this
-- !select --
-test_ctas1 CREATE TABLE `test_ctas1` (\n `test_varchar` varchar(150)
NULL,\n `test_datetime` datetime NULL,\n `test_default_timestamp` datetime
NULL DEFAULT CURRENT_TIMESTAMP\n) ENGINE=OLAP\nDUPLICATE
KEY(`test_varchar`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY HASH(`test_varchar`)
BUCKETS 10\nPROPERTIES (\n"replication_allocation" = "tag.location.default:
1",\n"in_memory" = "false",\n"storage_format" =
"V2",\n"disable_auto_compaction" = "false"\n);
+test_ctas1 CREATE TABLE `test_ctas1` (\n `test_varchar` varchar(150)
NULL,\n `test_text` text NULL,\n `test_datetime` datetime NULL,\n
`test_default_timestamp` datetime NULL DEFAULT CURRENT_TIMESTAMP\n)
ENGINE=OLAP\nDUPLICATE KEY(`test_varchar`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY
HASH(`test_varchar`) BUCKETS 10\nPROPERTIES (\n"replication_allocation" =
"tag.location.default: 1",\n"in_memory" = "false",\n"storage_format" =
"V2",\n"disable_auto_compaction" = "false"\n);
+
+-- !select --
+2
+
+-- !select --
+test_ctas2 CREATE TABLE `test_ctas2` (\n `test_varchar` varchar(150)
NULL,\n `test_text` text NULL,\n `test_datetime` datetime NULL,\n
`test_default_timestamp` datetime NULL DEFAULT CURRENT_TIMESTAMP\n)
ENGINE=OLAP\nDUPLICATE KEY(`test_varchar`)\nCOMMENT 'OLAP'\nDISTRIBUTED BY
HASH(`test_varchar`) BUCKETS 10\nPROPERTIES (\n"replication_allocation" =
"tag.location.default: 1",\n"in_memory" = "false",\n"storage_format" =
"V2",\n"disable_auto_compaction" = "false"\n);
-- !select --
2
diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy
b/regression-test/suites/ddl_p0/test_ctas.groovy
index 74403f7602..2a94e82b0e 100644
--- a/regression-test/suites/ddl_p0/test_ctas.groovy
+++ b/regression-test/suites/ddl_p0/test_ctas.groovy
@@ -20,6 +20,7 @@ suite("test_ctas") {
sql """
CREATE TABLE IF NOT EXISTS `test_ctas` (
`test_varchar` varchar(150) NULL,
+ `test_text` text NULL,
`test_datetime` datetime NULL,
`test_default_timestamp` datetime DEFAULT CURRENT_TIMESTAMP
) ENGINE=OLAP
@@ -32,7 +33,7 @@ suite("test_ctas") {
)
"""
- sql """ INSERT INTO test_ctas(test_varchar, test_datetime) VALUES
('test1','2022-04-27 16:00:33'),('test2','2022-04-27 16:00:54') """
+ sql """ INSERT INTO test_ctas(test_varchar, test_text, test_datetime)
VALUES ('test1','test11','2022-04-27 16:00:33'),('test2','test22','2022-04-27
16:00:54') """
sql """
CREATE TABLE IF NOT EXISTS `test_ctas1`
@@ -46,10 +47,26 @@ suite("test_ctas") {
qt_select """SHOW CREATE TABLE `test_ctas1`"""
qt_select """select count(*) from test_ctas1"""
+
+ sql """
+ CREATE TABLE IF NOT EXISTS `test_ctas2`
+ PROPERTIES (
+ "replication_allocation" = "tag.location.default: 1",
+ "in_memory" = "false",
+ "storage_format" = "V2"
+ ) as select test_varchar, lpad(test_text,10,'0') as test_text,
test_datetime, test_default_timestamp from test_ctas;
+ """
+
+ qt_select """SHOW CREATE TABLE `test_ctas2`"""
+
+ qt_select """select count(*) from test_ctas2"""
} finally {
sql """ DROP TABLE IF EXISTS test_ctas """
sql """ DROP TABLE IF EXISTS test_ctas1 """
+
+ sql """ DROP TABLE IF EXISTS test_ctas2 """
}
}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]