Add filter check for JDBC pushdown unit tests
JDBC filter pushdown always needs to preserve the original filter for
correctness. This is to prevent regressions like where filters
are partially pushed down and there is no guard on Presto side.
@@ -63,7 +63,9 @@ import org.testng.annotations.Test;
import java.sql.Types;
import java.util.Arrays;
+import java.util.LinkedList;
import java.util.Optional;
+import java.util.Queue;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -78,6 +80,7 @@ import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.function.Function.identity;
import static java.util.stream.Collectors.toMap;
+import static org.testng.Assert.assertTrue;
public class TestJdbcComputePushdown
{
@@ -259,6 +262,22 @@ public class TestJdbcComputePushdown
private static void assertPlanMatch(PlanNode actual, PlanMatchPattern expected, TypeProvider typeProvider)
{
+ // always check the actual plan node has a filter node to prevent accidentally missing predicates
+ Queue<PlanNode> nodes = new LinkedList<>(ImmutableSet.of(actual));
+ boolean hasFilterNode = false;
+ while (!nodes.isEmpty()) {
+ PlanNode node = nodes.poll();
+ nodes.addAll(node.getSources());
+
+ // we always enforce the original filter to be present
+ // the following assertPlan will guarantee the completeness of the filter
+ if (node instanceof FilterNode && node.getSources().get(0) instanceof TableScanNode) {
+ hasFilterNode = true;
+ break;
+ }
+ }
+ assertTrue(hasFilterNode, "filter is missing from the pushdown plan");
+
PlanAssert.assertPlan(
TEST_SESSION,
METADATA,
