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] fix split count distinct for null can't join #46563

Merged
merged 4 commits into from
Jan 10, 2025
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 @@ -24,9 +24,9 @@
import org.apache.doris.nereids.trees.copier.DeepCopierContext;
import org.apache.doris.nereids.trees.copier.LogicalPlanDeepCopier;
import org.apache.doris.nereids.trees.expressions.Alias;
import org.apache.doris.nereids.trees.expressions.EqualTo;
import org.apache.doris.nereids.trees.expressions.Expression;
import org.apache.doris.nereids.trees.expressions.NamedExpression;
import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
import org.apache.doris.nereids.trees.expressions.OrderExpression;
import org.apache.doris.nereids.trees.expressions.Slot;
import org.apache.doris.nereids.trees.expressions.functions.agg.AggregateFunction;
Expand Down Expand Up @@ -273,15 +273,15 @@ private static LogicalJoin<Plan, Plan> constructJoin(List<LogicalAggregate<Plan>
List<Slot> rightSlots = newAggs.get(1).getOutput();
List<Expression> hashConditions = new ArrayList<>();
for (int i = 0; i < len; ++i) {
hashConditions.add(new EqualTo(leftSlots.get(i), rightSlots.get(i)));
hashConditions.add(new NullSafeEqual(leftSlots.get(i), rightSlots.get(i)));
}
join = new LogicalJoin<>(JoinType.INNER_JOIN, hashConditions, newAggs.get(0), newAggs.get(1), null);
for (int j = 2; j < newAggs.size(); ++j) {
List<Slot> belowJoinSlots = join.left().getOutput();
List<Slot> belowRightSlots = newAggs.get(j).getOutput();
List<Expression> aboveHashConditions = new ArrayList<>();
for (int i = 0; i < len; ++i) {
aboveHashConditions.add(new EqualTo(belowJoinSlots.get(i), belowRightSlots.get(i)));
aboveHashConditions.add(new NullSafeEqual(belowJoinSlots.get(i), belowRightSlots.get(i)));
}
join = new LogicalJoin<>(JoinType.INNER_JOIN, aboveHashConditions, join, newAggs.get(j), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.doris.nereids.rules.rewrite;

import org.apache.doris.nereids.trees.expressions.NullSafeEqual;
import org.apache.doris.nereids.trees.plans.JoinType;
import org.apache.doris.nereids.trees.plans.Plan;
import org.apache.doris.nereids.util.MatchingUtils;
import org.apache.doris.nereids.util.MemoPatternMatchSupported;
Expand Down Expand Up @@ -180,6 +182,8 @@ void countMultiColumnsWithGby() {
physicalHashAggregate(
physicalDistribute(
physicalHashAggregate(any()))))
).when(join ->
join.getJoinType() == JoinType.INNER_JOIN && join.getHashJoinConjuncts().get(0) instanceof NullSafeEqual
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
--PhysicalCteProducer ( cteId=CTEId#0 )
----PhysicalOlapScan[test_distinct_multi]
--PhysicalResultSink
----hashJoin[INNER_JOIN] hashCondition=((.d = .d)) otherCondition=()
----hashJoin[INNER_JOIN] hashCondition=((.d <=> .d)) otherCondition=()
------hashAgg[DISTINCT_LOCAL]
--------hashAgg[GLOBAL]
----------hashAgg[LOCAL]
Expand Down Expand Up @@ -415,9 +415,9 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
--PhysicalCteProducer ( cteId=CTEId#0 )
----PhysicalOlapScan[test_distinct_multi]
--PhysicalResultSink
----hashJoin[INNER_JOIN] hashCondition=((.d = .d)) otherCondition=()
------hashJoin[INNER_JOIN] hashCondition=((.d = .d)) otherCondition=()
--------hashJoin[INNER_JOIN] hashCondition=((.d = .d)) otherCondition=()
----hashJoin[INNER_JOIN] hashCondition=((.d <=> .d)) otherCondition=()
------hashJoin[INNER_JOIN] hashCondition=((.d <=> .d)) otherCondition=()
--------hashJoin[INNER_JOIN] hashCondition=((.d <=> .d)) otherCondition=()
----------hashAgg[DISTINCT_LOCAL]
------------hashAgg[GLOBAL]
--------------hashAgg[LOCAL]
Expand Down Expand Up @@ -463,7 +463,7 @@ PhysicalCteAnchor ( cteId=CTEId#0 )
--PhysicalResultSink
----hashAgg[GLOBAL]
------hashAgg[LOCAL]
--------hashJoin[INNER_JOIN] hashCondition=((.c = .c)) otherCondition=()
--------hashJoin[INNER_JOIN] hashCondition=((.c <=> .c)) otherCondition=()
----------hashAgg[DISTINCT_LOCAL]
------------hashAgg[GLOBAL]
--------------hashAgg[LOCAL]
Expand Down Expand Up @@ -498,3 +498,6 @@ PhysicalResultSink
------PhysicalRepeat
--------PhysicalOlapScan[test_distinct_multi]

-- !null_hash --
1 \N 0 0.0

Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,10 @@ suite("distinct_split") {
group by grouping sets((a,b),(c));"""
exception "The query contains multi count distinct or sum distinct, each can't have multi columns"
}
}

//----------------test null hash join ------------------------
sql "drop table if exists test_distinct_multi_null_hash;"
sql "create table test_distinct_multi_null_hash(a int, b int, c int, d varchar(10), e date) distributed by hash(a) properties('replication_num'='1');"
sql "insert into test_distinct_multi_null_hash values(1,null,null,null,'2024-12-08');"
qt_null_hash "SELECT a, b, count(distinct c,e), count(distinct concat(d,e))/count(distinct e) FROM test_distinct_multi_null_hash where e = '2024-12-08' GROUP BY a, b;"
}
Loading