Skip to content
Closed
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 @@ -45,6 +45,7 @@
import static io.trino.sql.planner.SymbolsExtractor.extractUnique;
import static io.trino.sql.planner.iterative.Rule.Context;
import static io.trino.sql.planner.iterative.Rule.Result;
import static io.trino.sql.planner.plan.Patterns.Join.type;
import static io.trino.sql.planner.plan.Patterns.filter;
import static io.trino.sql.planner.plan.Patterns.join;
import static io.trino.sql.planner.plan.Patterns.source;
Expand Down Expand Up @@ -84,10 +85,10 @@ public class PushInequalityFilterExpressionBelowJoinRuleSet
GREATER_THAN_OR_EQUAL,
LESS_THAN,
LESS_THAN_OR_EQUAL);
private static final Pattern<JoinNode> JOIN_PATTERN = join();
private static final Pattern<JoinNode> JOIN_PATTERN = join().with(type().equalTo(JoinNode.Type.INNER));
private static final Capture<JoinNode> JOIN_CAPTURE = newCapture();
private static final Pattern<FilterNode> FILTER_PATTERN = filter().with(source().matching(
join().capturedAs(JOIN_CAPTURE)));
join().with(type().equalTo(JoinNode.Type.INNER)).capturedAs(JOIN_CAPTURE)));

private final Metadata metadata;
private final TypeAnalyzer typeAnalyzer;
Expand Down
20 changes: 20 additions & 0 deletions core/trino-main/src/test/java/io/trino/sql/query/TestJoin.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,4 +225,24 @@ public void testOutputDuplicatesInsensitiveJoin()
values())
.with(JoinNode.class, JoinNode::isMaySkipOutputDuplicates)))));
}

@Test
public void testPredicateOverOuterJoin()
{
assertThat(assertions.query(
"SELECT 5 " +
"FROM (VALUES (1,'foo')) l(l1, l2) " +
"LEFT JOIN (VALUES (2,'bar')) r(r1, r2) " +
"ON l2 = r2 " +
"WHERE l1 >= COALESCE(r1, 0)"))
.matches("VALUES 5");

assertThat(assertions.query(
"SELECT 5 " +
"FROM (VALUES (2,'foo')) l(l1, l2) " +
"RIGHT JOIN (VALUES (1,'bar')) r(r1, r2) " +
"ON l2 = r2 " +
"WHERE r1 >= COALESCE(l1, 0)"))
.matches("VALUES 5");
}
}