Skip to content
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,6 +20,7 @@
import org.apache.doris.nereids.rules.Rule;
import org.apache.doris.nereids.rules.RuleType;
import org.apache.doris.nereids.trees.expressions.EqualPredicate;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.IsNull;
import org.apache.doris.nereids.trees.expressions.Not;
Expand Down Expand Up @@ -89,15 +90,16 @@ public Rule build() {
* TODO: is_not_null can also be inferred from A < B and so on
*/
conjunctsChanged |= join.getHashJoinConjuncts().stream()
.map(EqualPredicate.class::cast)
.filter(EqualTo.class::isInstance)
.map(EqualTo.class::cast)
.map(equalTo -> JoinUtils.swapEqualToForChildrenOrder(equalTo, join.left().getOutputSet()))
.anyMatch(equalTo -> createIsNotNullIfNecessary(equalTo, conjuncts));

JoinUtils.JoinSlotCoverageChecker checker = new JoinUtils.JoinSlotCoverageChecker(
join.left().getOutput(),
join.right().getOutput());
conjunctsChanged |= join.getOtherJoinConjuncts().stream()
.filter(EqualPredicate.class::isInstance)
.filter(EqualTo.class::isInstance)
.filter(equalTo -> checker.isHashJoinCondition((EqualPredicate) equalTo))
.map(equalTo -> JoinUtils.swapEqualToForChildrenOrder((EqualPredicate) equalTo,
join.left().getOutputSet()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ private Statistics computeRepeat(Repeat<? extends Plan> repeat) {
.setNumNulls(stats.numNulls < 0 ? stats.numNulls : stats.numNulls * groupingSetNum)
.setDataSize(stats.dataSize < 0 ? stats.dataSize : stats.dataSize * groupingSetNum);
return Pair.of(kv.getKey(), columnStatisticBuilder.build());
}).collect(Collectors.toMap(Pair::key, Pair::value));
}).collect(Collectors.toMap(Pair::key, Pair::value, (item1, item2) -> item1));
return new Statistics(rowCount < 0 ? rowCount : rowCount * groupingSetNum, columnStatisticMap);
}

Expand All @@ -827,7 +827,7 @@ private Statistics computeOneRowRelation(List<NamedExpression> projects) {
// TODO: compute the literal size
return Pair.of(project.toSlot(), statistic);
})
.collect(Collectors.toMap(Pair::key, Pair::value));
.collect(Collectors.toMap(Pair::key, Pair::value, (item1, item2) -> item1));
int rowCount = 1;
return new Statistics(rowCount, columnStatsMap);
}
Expand All @@ -842,7 +842,7 @@ private Statistics computeEmptyRelation(EmptyRelation emptyRelation) {
.setAvgSizeByte(0);
return Pair.of(project.toSlot(), columnStat.build());
})
.collect(Collectors.toMap(Pair::key, Pair::value));
.collect(Collectors.toMap(Pair::key, Pair::value, (item1, item2) -> item1));
int rowCount = 0;
return new Statistics(rowCount, columnStatsMap);
}
Expand Down Expand Up @@ -995,7 +995,7 @@ private Statistics computeWindow(Window windowOperator) {
}
}
return Pair.of(expr.toSlot(), value);
}).collect(Collectors.toMap(Pair::key, Pair::value));
}).collect(Collectors.toMap(Pair::key, Pair::value, (item1, item2) -> item1));
columnStatisticMap.putAll(childColumnStats);
return new Statistics(stats.getRowCount(), columnStatisticMap);
}
Expand Down
37 changes: 37 additions & 0 deletions regression-test/data/nereids_p0/join/test_outer_join.out
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,40 @@

-- !join --

-- !select --
0 \N \N
0 \N \N
0 \N \N
0 \N \N
0 \N \N
7 \N \N
7 \N \N
7 \N \N
7 \N \N
7 \N \N
8 -7357378 \N
8 -7357378 \N
8 -7357378 \N
8 -7357378 \N
8 -7357378 \N
12 -1066765 \N
12 -1066765 \N
12 -1066765 \N
12 -1066765 \N
12 -1066765 \N
13 -4828168 \N
13 -4828168 \N
13 -4828168 \N
13 -4828168 \N
13 -4828168 \N
14 \N \N
14 \N \N
14 \N \N
14 \N \N
14 \N \N
17 -67 \N
17 -67 \N
17 -67 \N
17 -67 \N
17 -67 \N

36 changes: 36 additions & 0 deletions regression-test/suites/nereids_p0/join/test_outer_join.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,40 @@ suite("test_outer_join", "nereids_p0") {
sql "DROP TABLE IF EXISTS ${tbl1}"
sql "DROP TABLE IF EXISTS ${tbl2}"
sql "DROP TABLE IF EXISTS ${tbl3}"

sql """DROP TABLE IF EXISTS table_20_undef_partitions2_keys3_properties4_distributed_by511"""
sql """DROP TABLE IF EXISTS table_20_undef_partitions2_keys3_properties4_distributed_by5"""
sql """DROP TABLE IF EXISTS table_20_undef_partitions2_keys3_properties4_distributed_by52"""

sql """create table table_20_undef_partitions2_keys3_properties4_distributed_by511 (
pk int,
col_int_undef_signed int ,
col_int_undef_signed2 int
) engine=olap
DUPLICATE KEY(pk, col_int_undef_signed)
distributed by hash(pk) buckets 10
properties("replication_num" = "1");"""
sql """create table table_20_undef_partitions2_keys3_properties4_distributed_by5 (
col_int_undef_signed int/*agg_type_placeholder*/ ,
col_int_undef_signed2 int/*agg_type_placeholder*/ ,
pk int/*agg_type_placeholder*/
) engine=olap
distributed by hash(pk) buckets 10
properties("replication_num" = "1");"""
sql """create table table_20_undef_partitions2_keys3_properties4_distributed_by52 (
pk int,
col_int_undef_signed int ,
col_int_undef_signed2 int
) engine=olap
DUPLICATE KEY(pk, col_int_undef_signed)
distributed by hash(pk) buckets 10
properties("replication_num" = "1");"""

sql """insert into table_20_undef_partitions2_keys3_properties4_distributed_by511(pk,col_int_undef_signed,col_int_undef_signed2) values (0,null,null),(1,-107,-2457422),(2,8286200,null),(3,18368,4386195),(4,-10561,7625),(5,null,4867223),(6,-31,28390),(7,null,null),(8,null,-7357378),(9,3603478,21),(10,4000423,118),(11,8153660,2),(12,null,-1066765),(13,null,-4828168),(14,-5083340,null),(15,85,-394),(16,3350274,-4843280),(17,-2460711,-67),(18,-24998,-113),(19,-72,-3137671);"""
sql """insert into table_20_undef_partitions2_keys3_properties4_distributed_by5(pk,col_int_undef_signed,col_int_undef_signed2) values (0,6447625,-1027468),(1,null,null),(2,31378,null),(3,9,8081971),(4,-7503885,null),(5,null,-20883),(6,null,110),(7,12780,-22854),(8,null,121),(9,7121676,113),(10,-13201,29890),(11,null,-72),(12,8150635,null),(13,null,-49),(14,8319897,null),(15,3239704,null),(16,-8463,21764),(17,null,-17255),(18,7123047,-110),(19,null,10);"""
sql """insert into table_20_undef_partitions2_keys3_properties4_distributed_by52(pk,col_int_undef_signed,col_int_undef_signed2) values (0,112,-15490),(1,973,-5913694),(2,null,-2259045),(3,null,null),(4,123,8378),(5,95,-16),(6,26099,-7768794),(7,31987,-2510),(8,null,28),(9,-50,-25696),(10,7367,37),(11,2707848,11007),(12,3,4023643),(13,-6478416,null),(14,4705,null),(15,-2399593,null),(16,-3102,4779393),(17,89,null),(18,-3296249,53),(19,26846,108);"""
qt_select """SELECT T1.pk, T1.col_int_undef_signed2, T2 . col_int_undef_signed FROM table_20_undef_partitions2_keys3_properties4_distributed_by511 AS T1
LEFT JOIN table_20_undef_partitions2_keys3_properties4_distributed_by5 AS T2 ON T1.col_int_undef_signed >= T2.col_int_undef_signed2
RIGHT JOIN table_20_undef_partitions2_keys3_properties4_distributed_by52 AS T3 ON T2.col_int_undef_signed2 <=> T3.col_int_undef_signed2
WHERE T3.pk >= 1 AND T1.pk <> 5 order by 1, 2, 3;"""
}