diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java index 942c3cce70d6df..531f873dfff747 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java @@ -17,6 +17,7 @@ package org.apache.doris.analysis; +import org.apache.doris.catalog.Column; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; @@ -79,8 +80,9 @@ public void analyze(Analyzer analyzer) throws UserException { Preconditions.checkArgument(outputs.size() == queryStmt.getResultExprs().size()); for (int i = 0; i < outputs.size(); ++i) { if (queryStmt.getResultExprs().get(i).getSrcSlotRef() != null) { - queryStmt.getResultExprs().get(i).getSrcSlotRef().getColumn() - .setIsAllowNull(outputs.get(i).isNullable()); + Column columnCopy = new Column(queryStmt.getResultExprs().get(i).getSrcSlotRef().getColumn()); + columnCopy.setIsAllowNull(outputs.get(i).isNullable()); + queryStmt.getResultExprs().get(i).getSrcSlotRef().getDesc().setColumn(columnCopy); } } ArrayList resultExprs = getQueryStmt().getResultExprs(); diff --git a/regression-test/suites/ddl_p0/test_ctas.groovy b/regression-test/suites/ddl_p0/test_ctas.groovy index 7c093aa4793593..221c69b2524b3b 100644 --- a/regression-test/suites/ddl_p0/test_ctas.groovy +++ b/regression-test/suites/ddl_p0/test_ctas.groovy @@ -230,9 +230,21 @@ suite("test_ctas") { sql 'insert into a values(1, \'ww\'), (2, \'zs\');' sql 'insert into b values(1, 22);' - sql 'create table c properties("replication_num"="1") as select a.id, a.name, b.age from a left join b on a.id = b.id;' + sql 'set enable_nereids_planner=false' + + sql 'create table c properties("replication_num"="1") as select b.id, a.name, b.age from a left join b on a.id = b.id;' - String desc = sql 'desc c' + String descC = sql 'desc c' + assertTrue(descC.contains('Yes')) + String descB = sql 'desc b' + assertTrue(descB.contains('No')) + + sql '''create table test_date_v2 + properties ( + "replication_num"="1" + ) as select to_date('20250829'); + ''' + String desc = sql 'desc test_date_v2' assertTrue(desc.contains('Yes')) } finally { sql 'drop table a'