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](Nereids) set operation output nullable maybe wrong #39109

Merged
merged 1 commit into from
Aug 9, 2024
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 @@ -26,7 +26,6 @@
import org.apache.doris.nereids.trees.expressions.OrderExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.expressions.functions.ExpressionTrait;
import org.apache.doris.nereids.trees.expressions.functions.Function;
import org.apache.doris.nereids.trees.expressions.visitor.DefaultExpressionRewriter;
import org.apache.doris.nereids.trees.plans.Plan;
Expand Down Expand Up @@ -59,7 +58,6 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* because some rule could change output's nullable.
Expand Down Expand Up @@ -168,8 +166,10 @@ public Plan visitLogicalSetOperation(LogicalSetOperation setOperation, Map<ExprI
ImmutableList.Builder<List<SlotReference>> newChildrenOutputs = ImmutableList.builder();
List<Boolean> inputNullable = null;
if (!setOperation.children().isEmpty()) {
inputNullable = setOperation.getRegularChildOutput(0).stream()
.map(ExpressionTrait::nullable).collect(Collectors.toList());
inputNullable = Lists.newArrayListWithCapacity(setOperation.getOutputs().size());
for (int i = 0; i < setOperation.getOutputs().size(); i++) {
inputNullable.add(false);
}
for (int i = 0; i < setOperation.arity(); i++) {
List<Slot> childOutput = setOperation.child(i).getOutput();
List<SlotReference> setChildOutput = setOperation.getRegularChildOutput(i);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,84 @@
suite("test_set_operation_adjust_nullable") {

sql """
DROP TABLE IF EXISTS t1
DROP TABLE IF EXISTS set_operation_t1
"""
sql """
DROP TABLE IF EXISTS t2
DROP TABLE IF EXISTS set_operation_t2
"""

sql """
CREATE TABLE t1(c1 varchar) DISTRIBUTED BY hash(c1) PROPERTIES ("replication_num" = "1");
CREATE TABLE set_operation_t1(c1 varchar) DISTRIBUTED BY hash(c1) PROPERTIES ("replication_num" = "1");
"""

sql """
CREATE TABLE t2(c2 date) DISTRIBUTED BY hash(c2) PROPERTIES ("replication_num" = "1");
CREATE TABLE set_operation_t2(c2 date) DISTRIBUTED BY hash(c2) PROPERTIES ("replication_num" = "1");
"""

sql """
insert into t1 values('+06-00');
insert into set_operation_t1 values('+06-00');
"""

sql """
insert into t2 values('1990-11-11');
insert into set_operation_t2 values('1990-11-11');
"""

sql """
SELECT c1, c1 FROM t1 MINUS SELECT c2, c2 FROM t2;
SELECT c1, c1 FROM set_operation_t1 MINUS SELECT c2, c2 FROM set_operation_t2;
"""

// do not use regulator child output nullable as init nullable info

sql """
DROP TABLE IF EXISTS set_operation_t1
"""
sql """
DROP TABLE IF EXISTS set_operation_t2
"""

sql """
create table set_operation_t1 (
pk int,
c1 char(25) not null ,
c2 varchar(100) null ,
)
distributed by hash(pk) buckets 10
properties("replication_num" = "1");
"""

sql """insert into set_operation_t1 values (1, '1', '1');"""

sql """
create table set_operation_t2 (
c3 varchar(100) not null ,
pk int
)
distributed by hash(pk) buckets 10
properties("replication_num" = "1");
"""

sql """insert into set_operation_t2 values ('1', 1);"""

sql """
select
c2,
c1
from
set_operation_t1
order by
1,
2 asc
limit
0
union distinct
select
c3,
c3
from
set_operation_t2
except
select
'LDvlqYTfrq',
'rVdUjeSaJW';
"""
}
Loading