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

    https://github.com/apache/spark/pull/18542#discussion_r125671769
  
    --- 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 --
    
    Even the outputPartitioning guarantees the bucket spec, doesn't it just 
guarantee the rows with same bucket are put into same partition? I think it 
doesn't guarantee the rows of the same bucket are put continuously.


---
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