Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix](planner)fix incorrect nullable in ctas. #22770

Merged
merged 11 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.UserException;
import org.apache.doris.planner.OriginalPlanner;
import org.apache.doris.planner.PlanFragment;
import org.apache.doris.qe.ConnectContext;

import com.google.common.base.Preconditions;
import lombok.Getter;

import java.util.ArrayList;
Expand Down Expand Up @@ -67,6 +71,18 @@ public void analyze(Analyzer analyzer) throws UserException {
QueryStmt tmpStmt = queryStmt.clone();
tmpStmt.analyze(dummyRootAnalyzer);
this.queryStmt = tmpStmt;
// to adjust the nullable of the result expression, we have to create plan fragment from the query stmt.
OriginalPlanner planner = new OriginalPlanner(dummyRootAnalyzer);
planner.createPlanFragments(queryStmt, dummyRootAnalyzer, ConnectContext.get().getSessionVariable().toThrift());
PlanFragment root = planner.getFragments().get(0);
List<Expr> outputs = root.getOutputExprs();
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());
}
}
ArrayList<Expr> resultExprs = getQueryStmt().getResultExprs();
if (columnNames != null && columnNames.size() != resultExprs.size()) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_COL_NUMBER_NOT_MATCH);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ private PlanNode createJoinPlan(Analyzer analyzer, TableRef leftmostRef, List<Pa
// reset assigned conjuncts of analyzer in every compare
analyzer.setAssignedConjuncts(root.getAssignedConjuncts());
PlanNode candidate = createJoinNode(analyzer, root, rootPlanNodeOfCandidate, tblRefOfCandidate);
// (ML): 这里还需要吗?应该不会返回null吧
// it may not return null, but protect.
if (candidate == null) {
continue;
}
Expand Down
33 changes: 33 additions & 0 deletions regression-test/suites/ddl_p0/test_ctas.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,39 @@ suite("test_ctas") {
DROP TABLE IF EXISTS ctas_113815
"""
}

try {
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 '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;'

String desc = sql 'desc c'
assertTrue(desc.contains('Yes'))
} finally {
sql 'drop table a'
sql 'drop table b'
sql 'drop table c'
}
}

2 changes: 1 addition & 1 deletion regression-test/suites/delete_p0/test_delete.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ suite("test_delete") {
PROPERTIES (
"replication_num" = "1",
"enable_unique_key_merge_on_write" = "true"
);
);
'''

sql 'insert into test1 values("a", "a"), ("bb", "bb"), ("ccc", "ccc")'
Expand Down
Loading