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

    https://github.com/apache/spark/pull/10498#discussion_r48951109
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/WriterContainer.scala
 ---
    @@ -335,6 +339,117 @@ private[sql] class DynamicPartitionWriterContainer(
           val partitionName = Literal(c.name + "=") :: str :: Nil
           if (i == 0) partitionName else Literal(Path.SEPARATOR) :: 
partitionName
         }
    +  }
    +
    +  private def getBucketIdFromKey(key: InternalRow): Option[Int] = {
    +    if (bucketSpec.isDefined) {
    +      Some(key.getInt(partitionColumns.length))
    +    } else {
    +      None
    +    }
    +  }
    +
    +  private def sameBucket(key1: UnsafeRow, key2: UnsafeRow): Boolean = {
    +    val bucketIdIndex = partitionColumns.length
    +    if (key1.getInt(bucketIdIndex) != key2.getInt(bucketIdIndex)) {
    +      false
    +    } else {
    +      var i = partitionColumns.length - 1
    +      while (i >= 0) {
    +        val dt = partitionColumns(i).dataType
    +        if (key1.get(i, dt) != key2.get(i, dt)) return false
    +        i -= 1
    +      }
    +      true
    +    }
    +  }
    +
    +  private def sortBasedWrite(
    +      sorter: UnsafeKVExternalSorter,
    +      iterator: Iterator[InternalRow],
    +      getSortingKey: UnsafeProjection,
    +      getOutputRow: UnsafeProjection,
    +      getPartitionString: UnsafeProjection,
    +      outputWriters: java.util.HashMap[InternalRow, OutputWriter]): Unit = 
{
    +    while (iterator.hasNext) {
    +      val currentRow = iterator.next()
    +      sorter.insertKV(getSortingKey(currentRow), getOutputRow(currentRow))
    +    }
    +
    +    logInfo(s"Sorting complete. Writing out partition files one at a 
time.")
    +
    +    val needNewWriter: (UnsafeRow, UnsafeRow) => Boolean = if 
(sortColumns.isEmpty) {
    +      (key1, key2) => key1 != key2
    +    } else {
    +      (key1, key2) => key1 == null || !sameBucket(key1, key2)
    +    }
    +
    +    val sortedIterator = sorter.sortedIterator()
    +    var currentKey: UnsafeRow = null
    +    var currentWriter: OutputWriter = null
    +    try {
    +      while (sortedIterator.next()) {
    +        if (needNewWriter(currentKey, sortedIterator.getKey)) {
    --- End diff --
    
    I'm a little worried here. It was a simple `!=` operator for non-bucket 
path before, but now it's a function call.


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