Skip to content
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 @@ -159,13 +159,14 @@ public PlanOptimizerResult optimize(PlanNode plan, Session session, TypeProvider
}
optimizersWithConnectorRange.put(currentConnectors, currentGroup.build());

ImmutableMap.Builder<PlanNode, ConnectorPlanNodeContext> contextMapBuilder = ImmutableMap.builder();
buildConnectorPlanNodeContext(plan, null, contextMapBuilder);
Map<PlanNode, ConnectorPlanNodeContext> contextMap = contextMapBuilder.build();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This contextMap is used for all iterations of the for loop below, hence missing the changes made by previous iterations

for (Map.Entry<List<ConnectorId>, Set<ConnectorPlanOptimizer>> entry : optimizersWithConnectorRange.build().entrySet()) {
// keep track of changed nodes; the keys are original nodes and the values are the new nodes
Map<PlanNode, PlanNode> updates = new HashMap<>();

ImmutableMap.Builder<PlanNode, ConnectorPlanNodeContext> contextMapBuilder = ImmutableMap.builder();
buildConnectorPlanNodeContext(plan, null, contextMapBuilder);
Map<PlanNode, ConnectorPlanNodeContext> contextMap = contextMapBuilder.build();

// process connector optimizers
for (PlanNode node : contextMap.keySet()) {
// For a subtree with root `node` to be a max closure, the following conditions must hold:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,28 @@ public void testMultipleConnectorOptimization()
SimpleTableScanMatcher.tableScan("cat2", "a", "b")),
SimpleTableScanMatcher.tableScan("cat3", TRUE_CONSTANT))));

plan = output(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test will fail without the fix in this PR

union(
union(
tableScan("cat1", "a", "b"),
tableScan("cat2", "a", "b")),
filter(tableScan("cat1", "a", "b"), TRUE_CONSTANT)),
"a");

actual = optimize(plan, ImmutableMap.of(
new ConnectorId("cat1"), ImmutableSet.of(multiConnectorOptimizer12, filterPushdown())));

assertPlanMatch(
actual,
PlanMatchPattern.output(
PlanMatchPattern.union(
PlanMatchPattern.union(
SimpleTableScanMatcher.tableScan("cat1", TRUE_CONSTANT),
PlanMatchPattern.filter(
"true",
SimpleTableScanMatcher.tableScan("cat2", "a", "b"))),
SimpleTableScanMatcher.tableScan("cat1", TRUE_CONSTANT))));

plan = output(
union(
union(
Expand Down
Loading