Skip to content

Commit

Permalink
[fix](planner) ctas should not change any meta of column in source ta…
Browse files Browse the repository at this point in the history
…ble (#24767)

if previous PR #22770. we try to fix incorrect nullable in target table.
However we changed nullable info of column in source table unexpectly
  • Loading branch information
morrySnow authored and morningman committed Sep 23, 2023
1 parent 8683ea5 commit 600ce53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,8 +79,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<Expr> resultExprs = getQueryStmt().getResultExprs();
Expand Down
10 changes: 7 additions & 3 deletions regression-test/suites/ddl_p0/test_ctas.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,14 @@ 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'
assertTrue(desc.contains('Yes'))
String descC = sql 'desc c'
assertTrue(descC.contains('Yes'))
String descB = sql 'desc b'
assertTrue(descB.contains('No'))
} finally {
sql 'drop table a'
sql 'drop table b'
Expand Down

0 comments on commit 600ce53

Please sign in to comment.