diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java index 71a0ed39d7e37..3ac46e12a12e0 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java @@ -34,6 +34,7 @@ import com.facebook.presto.spi.plan.OrderingScheme; import com.facebook.presto.spi.plan.OutputNode; import com.facebook.presto.spi.plan.PlanNode; +import com.facebook.presto.spi.plan.PlanNodeId; import com.facebook.presto.spi.plan.PlanNodeIdAllocator; import com.facebook.presto.spi.plan.ProjectNode; import com.facebook.presto.spi.plan.TableScanNode; @@ -107,7 +108,10 @@ public class CanonicalPlanGenerator extends InternalPlanVisitor, CanonicalPlanGenerator.Context> { - private final PlanNodeIdAllocator planNodeidAllocator = new PlanNodeIdAllocator(); + private static final String CANONICAL_STRING = "CANONICAL"; + + // Not using a new override to objectMapper because PlanNodeId has a JsonValue annotation which cannot be directly overriden in a serializer + private final PlanNodeIdAllocator planNodeidAllocator; private final VariableAllocator variableAllocator = new VariableAllocator(); // TODO: DEFAULT strategy has a very different canonicalizaiton implementation, refactor it into a separate class. private final PlanCanonicalizationStrategy strategy; @@ -119,6 +123,26 @@ public CanonicalPlanGenerator(PlanCanonicalizationStrategy strategy, ObjectMappe this.strategy = requireNonNull(strategy, "strategy is null"); this.objectMapper = requireNonNull(objectMapper, "objectMapper is null"); this.session = requireNonNull(session, "session is null"); + this.planNodeidAllocator = createPlanNodeIdAllocator(strategy); + } + + private PlanNodeIdAllocator createPlanNodeIdAllocator(PlanCanonicalizationStrategy strategy) + { + //ToDO: For HBO we always want planNodeId to be canonicalized but currently fragment result caching is using the same class with default strategy + // refactor the default strategy to a different class + if (strategy.equals(DEFAULT)) { + return new PlanNodeIdAllocator(); + } + else { + return new PlanNodeIdAllocator() + { + @Override + public PlanNodeId getNextId() + { + return new PlanNodeId(CANONICAL_STRING); + } + }; + } } public static Optional generateCanonicalPlanFragment(PlanNode root, PartitioningScheme partitioningScheme, ObjectMapper objectMapper, Session session)