Github user pwoody commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18542#discussion_r125718916
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/FileFormatWriter.scala
 ---
    @@ -116,13 +116,24 @@ object FileFormatWriter extends Logging {
         val partitionSet = AttributeSet(partitionColumns)
         val dataColumns = allColumns.filterNot(partitionSet.contains)
     
    -    val bucketIdExpression = bucketSpec.map { spec =>
    +    val bucketPartitioning = bucketSpec.map { spec =>
           val bucketColumns = spec.bucketColumnNames.map(c => 
dataColumns.find(_.name == c).get)
    +      HashPartitioning(bucketColumns, spec.numBuckets)
    +    }
    +
    +    val bucketIdExpression = bucketPartitioning.map { partitioning =>
           // Use `HashPartitioning.partitionIdExpression` as our bucket id 
expression, so that we can
           // guarantee the data distribution is same between shuffle and 
bucketed data source, which
           // enables us to only shuffle one side when join a bucketed table 
and a normal one.
    -      HashPartitioning(bucketColumns, 
spec.numBuckets).partitionIdExpression
    +      partitioning.partitionIdExpression
         }
    +
    +    // If the outputPartitioning for the plan guarantees the bucket spec, 
then it will have a
    +    // constant bucket id. We possibly can avoid the sort altogether.
    +    val bucketSortExpression = bucketPartitioning
    +      .filterNot(plan.outputPartitioning.guarantees(_))
    +      .map(_.partitionIdExpression)
    --- End diff --
    
    Ah true, my mistake - we don't get that guarantee from partitioning alone. 
I can edit to be strict equality, which should get the most utility anyway 
(pipelines over the bucket spec or explicit partitioning in transform logic).
    
    As an aside, do we have a case w/ the current Partitioning implementations 
where guarantees(HashPartitioning) isn't going to have contiguous values?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

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

Reply via email to