pan3793 commented on code in PR #60755:
URL: https://github.com/apache/spark/pull/60755#discussion_r4643201488
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetWriteSupport.scala:
##########
@@ -284,7 +285,19 @@ class ParquetWriteSupport extends
WriteSupport[InternalRow] with Logging {
case BinaryType =>
(row: SpecializedGetters, ordinal: Int) =>
-
recordConsumer.addBinary(Binary.fromReusedByteArray(row.getBinary(ordinal)))
+ recordConsumer.addBinary(row match {
+ case _: UnsafeRow | _: UnsafeArrayData =>
+ val value = row.getBinaryView(ordinal)
+ value.getBaseObject match {
+ case bytes: Array[Byte] =>
+ // Mark the bytes as reused so Parquet copies values that it
retains.
+ Binary.fromReusedByteArray(bytes,
+ (value.getBaseOffset - Platform.BYTE_ARRAY_OFFSET).toInt,
value.numBytes())
+ case _ => Binary.fromConstantByteArray(value.getBytes)
+ }
+ // Other implementations store BinaryType as Array[Byte], not
BinaryView.
Review Comment:
nit: `ColumnarRow`, `ColumnarBatchRow`, `JoinedRow` and
`ProjectingInternalRow` also implement `getBinaryView`; only generic rows and
arrays hold `Array[Byte]`, where `getBinaryView` throws.
```suggestion
// Generic rows and arrays hold Array[Byte], so getBinaryView
would fail on them.
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]