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

    https://github.com/apache/spark/pull/7954#discussion_r36382000
  
    --- Diff: 
sql/core/src/main/scala/org/apache/spark/sql/execution/UnsafeRowSerializer.scala
 ---
    @@ -58,11 +58,26 @@ private class UnsafeRowSerializerInstance(numFields: 
Int) extends SerializerInst
        */
       override def serializeStream(out: OutputStream): SerializationStream = 
new SerializationStream {
         private[this] var writeBuffer: Array[Byte] = new Array[Byte](4096)
    +    // When `out` is backed by ChainedBufferOutputStream, we will get an
    +    // UnsupportedOperationException when we call dOut.writeInt because it 
internally calls
    +    // ChainedBufferOutputStream's write(b: Int), which is not supported.
    +    // To workaround this issue, we create an array for sorting the int 
value.
    +    // To reproduce the problem, use dOut.writeInt(row.getSizeInBytes) and
    +    // run SparkSqlSerializer2SortMergeShuffleSuite.
    +    private[this] var intBuffer: Array[Byte] = new Array[Byte](4)
         private[this] val dOut: DataOutputStream = new DataOutputStream(out)
     
         override def writeValue[T: ClassTag](value: T): SerializationStream = {
           val row = value.asInstanceOf[UnsafeRow]
    -      dOut.writeInt(row.getSizeInBytes)
    +      val size = row.getSizeInBytes
    +      // This part is based on DataOutputStream's writeInt.
    +      // It is for dOut.writeInt(row.getSizeInBytes).
    +      intBuffer(0) = ((size >>> 24) & 0xFF).toByte
    +      intBuffer(1) = ((size >>> 16) & 0xFF).toByte
    +      intBuffer(2) = ((size >>> 8) & 0xFF).toByte
    +      intBuffer(3) = ((size >>> 0) & 0xFF).toByte
    +      dOut.write(intBuffer, 0, 4)
    --- End diff --
    
    Also, we need to double check if we need to wrap input stream with a 
buffered input stream when we read data back.


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