Skip to content

Commit 98b4696

Browse files
authored
Skip EliminateCrossJoin rule when meet non-empty join filter (apache#4869)
* Skip EliminateCrossJoin rule when meet non-empty join filter * fix cargo fmt
1 parent 556282a commit 98b4696

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
##########
19+
## JOIN Tests
20+
##########
21+
22+
statement ok
23+
CREATE TABLE students(name TEXT, mark INT) AS VALUES
24+
('Stuart', 28),
25+
('Amina', 89),
26+
('Christen', 50),
27+
('Salma', 77),
28+
('Samantha', 21);
29+
30+
statement ok
31+
CREATE TABLE grades(grade INT, min INT, max INT) AS VALUES
32+
(1, 0, 14),
33+
(2, 15, 35),
34+
(3, 36, 55),
35+
(4, 56, 79),
36+
(5, 80, 100);
37+
38+
# Regression test: https://github.com/apache/arrow-datafusion/issues/4844
39+
query I
40+
SELECT s.*, g.grade FROM students s join grades g on s.mark between g.min and g.max WHERE grade > 2 ORDER BY s.mark DESC
41+
----
42+
Amina 89 5
43+
Salma 77 4
44+
Christen 50 3

datafusion/optimizer/src/eliminate_cross_join.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ impl OptimizerRule for EliminateCrossJoin {
6262
let mut all_inputs: Vec<LogicalPlan> = vec![];
6363
match &input {
6464
LogicalPlan::Join(join) if (join.join_type == JoinType::Inner) => {
65+
// The filter of inner join will lost, skip this rule.
66+
// issue: https://github.com/apache/arrow-datafusion/issues/4844
67+
if join.filter.is_some() {
68+
return Ok(None);
69+
}
70+
6571
flatten_join_inputs(
6672
&input,
6773
&mut possible_join_keys,

0 commit comments

Comments
 (0)