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

    https://github.com/apache/spark/pull/11759#discussion_r56611911
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkPlan.scala ---
    @@ -218,48 +218,64 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] 
with Logging with Serializ
       }
     
       /**
    -   * Runs this query returning the result as an array.
    +   * Packing the UnsafeRows into byte array for faster serialization.
    +   * The byte arrays are in the following format:
    +   * [size] [bytes of UnsafeRow] [size] [bytes of UnsafeRow] ... [-1]
    +   *
    +   * UnsafeRow is highly compressible (at least 8 bytes for any column), 
the byte array is also
    +   * compressed.
        */
    -  def executeCollect(): Array[InternalRow] = {
    -    // Packing the UnsafeRows into byte array for faster serialization.
    -    // The byte arrays are in the following format:
    -    // [size] [bytes of UnsafeRow] [size] [bytes of UnsafeRow] ... [-1]
    -    //
    -    // UnsafeRow is highly compressible (at least 8 bytes for any column), 
the byte array is also
    -    // compressed.
    -    val byteArrayRdd = execute().mapPartitionsInternal { iter =>
    +  private def getByteArrayRdd(n: Int = -1): RDD[Array[Byte]] = {
    +    execute().mapPartitionsInternal { iter =>
    +      var count = 0
           val buffer = new Array[Byte](4 << 10)  // 4K
           val codec = CompressionCodec.createCodec(SparkEnv.get.conf)
           val bos = new ByteArrayOutputStream()
           val out = new DataOutputStream(codec.compressedOutputStream(bos))
    -      while (iter.hasNext) {
    +      while (iter.hasNext && (n < 0 || count < n)) {
             val row = iter.next().asInstanceOf[UnsafeRow]
             out.writeInt(row.getSizeInBytes)
             row.writeToStream(out, buffer)
    +        count += 1
           }
           out.writeInt(-1)
           out.flush()
           out.close()
           Iterator(bos.toByteArray)
         }
    +  }
     
    -    // Collect the byte arrays back to driver, then decode them as 
UnsafeRows.
    +  /**
    +   * Collect the byte arrays back to driver, then decode them as 
UnsafeRows.
    +   */
    +  private def collectRowFromBytes(bytes: Array[Byte]): Array[InternalRow] 
= {
    --- End diff --
    
    done with decodeUnsafeRow.


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