Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10498#discussion_r48591458
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/WriterContainer.scala
 ---
    @@ -317,14 +318,39 @@ private[sql] class DynamicPartitionWriterContainer(
         isAppend: Boolean)
       extends BaseWriterContainer(relation, job, isAppend) {
     
    +  private def toAttribute(columnName: String) = inputSchema.find(_.name == 
columnName).get
    +
       def writeRows(taskContext: TaskContext, iterator: 
Iterator[InternalRow]): Unit = {
         val outputWriters = new java.util.HashMap[InternalRow, OutputWriter]
         executorSideSetup(taskContext)
     
         var outputWritersCleared = false
     
    -    // Returns the partition key given an input row
    -    val getPartitionKey = UnsafeProjection.create(partitionColumns, 
inputSchema)
    +    val getKey = if (bucketSpec.isEmpty) {
    +      UnsafeProjection.create(partitionColumns, inputSchema)
    +    } else {
    +      val BucketSpec(numBuckets, bucketColumns, sortColumns) = 
bucketSpec.get
    +      val bucketIdExpr = Pmod(Hash(bucketColumns.map(toAttribute)), 
Literal(numBuckets))
    +      val sortingAttrs = sortColumns.map(_.map(toAttribute)).getOrElse(Nil)
    +      UnsafeProjection.create(partitionColumns ++ (bucketIdExpr +: 
sortingAttrs), inputSchema)
    --- End diff --
    
    The logic is: if we have sorting columns, then we will immediately sort 
input rows, and won't use the hash map to keep all writers.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to