Skip to content

Commit

Permalink
Remove dynamic filters with expression which are not a SymbolReference
Browse files Browse the repository at this point in the history
  • Loading branch information
raunaqmorarka authored and sopel39 committed Jun 10, 2020
1 parent acdf5e3 commit d656383
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import io.prestosql.sql.tree.ExpressionRewriter;
import io.prestosql.sql.tree.ExpressionTreeRewriter;
import io.prestosql.sql.tree.LogicalBinaryExpression;
import io.prestosql.sql.tree.SymbolReference;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -222,7 +223,8 @@ private Expression removeDynamicFilters(Expression expression, Set<String> allow
.filter(conjunct ->
getDescriptor(conjunct)
.map(descriptor -> {
if (allowedDynamicFilterIds.contains(descriptor.getId())) {
if (descriptor.getInput() instanceof SymbolReference &&
allowedDynamicFilterIds.contains(descriptor.getId())) {
consumedDynamicFilterIds.add(descriptor.getId());
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import io.prestosql.sql.planner.plan.PlanVisitor;
import io.prestosql.sql.planner.plan.TableScanNode;
import io.prestosql.sql.tree.Expression;
import io.prestosql.sql.tree.SymbolReference;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -104,9 +105,10 @@ public Set<String> visitFilter(FilterNode node, Void context)
verify(node.getSource() instanceof TableScanNode, "Dynamic filters %s present in filter predicate whose source is not a table scan.", dynamicFilters);
}
ImmutableSet.Builder<String> consumed = ImmutableSet.builder();
dynamicFilters.stream()
.map(DynamicFilters.Descriptor::getId)
.forEach(consumed::add);
dynamicFilters.forEach(descriptor -> {
verify(descriptor.getInput() instanceof SymbolReference, "Dynamic filter expression must be a SymbolReference");
consumed.add(descriptor.getId());
});
consumed.addAll(node.getSource().accept(this, context));
return consumed.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,8 @@ public void testJoinOnCast()
node(
JoinNode.class,
anyTree(
node(
FilterNode.class,
tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")))
.with(numberOfDynamicFilters(1))),
project(
tableScan("orders", ImmutableMap.of("ORDERS_OK", "orderkey")))),
anyTree(
tableScan("lineitem", ImmutableMap.of("LINEITEM_OK", "orderkey"))))));
}
Expand Down

0 comments on commit d656383

Please sign in to comment.