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 predicate pushdown for identity projections #1515

Merged
merged 1 commit into from
Sep 25, 2019
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 @@ -277,7 +277,7 @@ private boolean isInliningCandidate(Expression expression, ProjectNode node)
verify(AstUtils.preOrder(expression).noneMatch(TryExpression.class::isInstance));

// candidate symbols for inlining are
// 1. references to simple constants
// 1. references to simple constants or symbol references
// 2. references to complex expressions that appear only once
// which come from the node, as opposed to an enclosing scope.
Set<Symbol> childOutputSet = ImmutableSet.copyOf(node.getOutputSymbols());
Expand All @@ -286,7 +286,9 @@ private boolean isInliningCandidate(Expression expression, ProjectNode node)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

return dependencies.entrySet().stream()
.allMatch(entry -> entry.getValue() == 1 || node.getAssignments().get(entry.getKey()) instanceof Literal);
.allMatch(entry -> entry.getValue() == 1
|| node.getAssignments().get(entry.getKey()) instanceof Literal
|| node.getAssignments().get(entry.getKey()) instanceof SymbolReference);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,19 @@ public void testPredicatePushDownOverProjection()
"ORDERKEY", "orderkey"))))));
}

@Test
public void testPredicatePushDownOverSymbolReferences()
{
// Identities should be pushed down
assertPlan(
"WITH t AS (SELECT orderkey x, (orderkey + 1) x2 FROM orders) " +
"SELECT * FROM t WHERE x > 1 OR x < 0",
anyTree(
filter("orderkey < BIGINT '0' OR orderkey > BIGINT '1'",
tableScan("orders", ImmutableMap.of(
"orderkey", "orderkey")))));
}

@Test
public void testConjunctsOrder()
{
Expand Down