EnricoMi opened a new pull request, #39673:
URL: https://github.com/apache/spark/pull/39673

   ### What changes were proposed in this pull request?
   This deduplicate attributes that exist on both sides of a `CoGroup` by 
aliasing the occurrence on the right side.
   
   ### Why are the changes needed?
   Usually, DeduplicateRelations rule does exactly this. But the generic 
`QueryPlan.rewriteAttrs` replaces all occurrences of the duplicate reference 
with the new reference, but `CoGroup` uses the old reference for left and right 
group attributes, value attributes, and group order. Only the occurrences in 
the right attributes must be replaced.
   
   Further, the right deserialization expression is not touched at all.
   
   The following DataFrame cannot be evaluated:
   ```scala
   val df = spark.range(3)
   
   val left_grouped_df = df.groupBy("id").as[Long, Long]
   val right_grouped_df = df.groupBy("id").as[Long, Long]
   
   val cogroup_df = left_grouped_df.cogroup(right_grouped_df) {
     case (key, left, right) => left
   }
   ```
   
   The query plan:
   ```
   == Physical Plan ==
   AdaptiveSparkPlan isFinalPlan=false
   +- SerializeFromObject [input[0, bigint, false] AS value#12L]
      +- CoGroup, id#0: bigint, id#0: bigint, id#0: bigint, [id#13L], [id#13L], 
[id#13L], [id#13L], obj#11: bigint
         :- !Sort [id#13L ASC NULLS FIRST], false, 0
         :  +- !Exchange hashpartitioning(id#13L, 200), ENSURE_REQUIREMENTS, 
[plan_id=16]
         :     +- Range (0, 3, step=1, splits=16)
         +- Sort [id#13L ASC NULLS FIRST], false, 0
            +- Exchange hashpartitioning(id#13L, 200), ENSURE_REQUIREMENTS, 
[plan_id=17]
               +- Range (0, 3, step=1, splits=16)
   ```
   
   ### Does this PR introduce _any_ user-facing change?
   This fixes correctness.
   
   ### How was this patch tested?
   Unit test in `DataFrameSuite`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to