@@ -31,16 +31,13 @@ import org.apache.spark.sql.catalyst.plans.logical.{Aggregate, Filter, Join, Log
3131 * - A newly merged plan combining the input with a cached plan
3232 * - The original input plan (if no merge was possible)
3333 * @param mergedPlanIndex The index of this plan in the PlanMerger's cache.
34- * @param merged Whether the plan was merged with an existing cached plan (true) or
35- * is a new entry (false).
3634 * @param outputMap Maps attributes from the input plan to corresponding attributes in
3735 * `mergedPlan`. Used to rewrite expressions referencing the original plan
3836 * to reference the merged plan instead.
3937 */
4038case class MergeResult (
41- mergedPlan : LogicalPlan ,
39+ mergedPlan : MergedPlan ,
4240 mergedPlanIndex : Int ,
43- merged : Boolean ,
4441 outputMap : AttributeMap [Attribute ])
4542
4643/**
@@ -75,7 +72,7 @@ case class MergedPlan(plan: LogicalPlan, merged: Boolean)
7572 * val merger = PlanMerger()
7673 * val result1 = merger.merge(plan1) // Adds plan1 to cache
7774 * val result2 = merger.merge(plan2) // Merges with plan1 if compatible
78- * // result2.merged == true if plans were merged
75+ * // result2.mergedPlan. merged == true if plans were merged
7976 * // result2.outputMap maps plan2's attributes to the merged plan's attributes
8077 * }}}
8178 */
@@ -94,26 +91,29 @@ class PlanMerger {
9491 * @return A [[MergeResult ]] containing:
9592 * - The merged/cached plan to use
9693 * - Its index in the cache
97- * - Whether it was merged with an existing plan
9894 * - An attribute mapping for rewriting expressions
9995 */
10096 def merge (plan : LogicalPlan ): MergeResult = {
10197 cache.zipWithIndex.collectFirst(Function .unlift {
10298 case (mp, i) =>
10399 checkIdenticalPlans(plan, mp.plan).map { outputMap =>
104- MergeResult (mp.plan, i, true , outputMap)
100+ val newMergePlan = MergedPlan (mp.plan, true )
101+ cache(i) = newMergePlan
102+ MergeResult (newMergePlan, i, outputMap)
105103 }.orElse {
106104 tryMergePlans(plan, mp.plan).map {
107105 case (mergedPlan, outputMap) =>
108- cache(i) = MergedPlan (mergedPlan, true )
109- MergeResult (mergedPlan, i, true , outputMap)
106+ val newMergePlan = MergedPlan (mergedPlan, true )
107+ cache(i) = newMergePlan
108+ MergeResult (newMergePlan, i, outputMap)
110109 }
111110 }
112111 case _ => None
113112 }).getOrElse {
114- cache += MergedPlan (plan, false )
113+ val newMergePlan = MergedPlan (plan, false )
114+ cache += newMergePlan
115115 val outputMap = AttributeMap (plan.output.map(a => a -> a))
116- MergeResult (plan , cache.length - 1 , false , outputMap)
116+ MergeResult (newMergePlan , cache.length - 1 , outputMap)
117117 }
118118 }
119119
@@ -297,7 +297,3 @@ class PlanMerger {
297297 }
298298 }
299299}
300-
301- object PlanMerger {
302- def apply (): PlanMerger = new PlanMerger
303- }
0 commit comments