Skip to content

Commit

Permalink
[fix](planner) ctas should not change any meta of column in source table
Browse files Browse the repository at this point in the history
if previous PR apache#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 committed Sep 22, 2023
1 parent cec3fcd commit f6824a2
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 6 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.catalog.ScalarType;
import org.apache.doris.catalog.Type;
import org.apache.doris.common.Config;
Expand Down Expand Up @@ -82,8 +83,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);
}
if (Config.enable_date_conversion) {
if (queryStmt.getResultExprs().get(i).getType() == Type.DATE) {
Expand Down
13 changes: 9 additions & 4 deletions regression-test/suites/ddl_p0/test_ctas.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +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'
assertTrue(desc.contains('Yes'))
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');
'''
desc = sql 'desc test_date_v2'
String desc = sql 'desc test_date_v2'
assertTrue(desc.contains('Yes'))
} finally {
sql 'drop table a'
Expand Down
51 changes: 51 additions & 0 deletions regression-test/suites/nereids_p0/create_table/test_ctas.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -222,5 +222,56 @@ suite("nereids_test_ctas") {
"""

qt_select """select * from ${table2} order by c1;"""

try {
sql "drop table if exists a"
sql "drop table if exists b"
sql "drop table if exists c"
sql "drop table if exists test_date_v2"
sql '''create table a (
id int not null,
name varchar(20) not null
)
distributed by hash(id) buckets 4
properties (
"replication_num"="1"
);
'''

sql '''create table b (
id int not null,
age int not null
)
distributed by hash(id) buckets 4
properties (
"replication_num"="1"
);
'''

sql 'insert into a values(1, \'ww\'), (2, \'zs\');'
sql 'insert into b values(1, 22);'

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 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'
sql 'drop table b'
sql 'drop table c'
sql 'drop table test_date_v2'
}
}

0 comments on commit f6824a2

Please sign in to comment.