saths008 commented on code in PR #59566:
URL: https://github.com/apache/spark/pull/59566#discussion_r4627742869
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/parquet/ParquetIOSuite.scala:
##########
@@ -164,6 +173,124 @@ class ParquetIOSuite extends ParquetTest with
SharedSparkSession {
withSQLConf(SQLConf.PARQUET_BINARY_AS_STRING.key ->
"true")(checkParquetFile(data))
}
+ test("SPARK-60321: string writer reuses the backing array of a UTF8String
slice") {
+ val consumer = mock(classOf[RecordConsumer])
+ val support = new ParquetWriteSupport
+ support.init(parquetStringWriterConf)
+ support.prepareForWrite(consumer)
+ val bytes = "prefix-value-suffix".getBytes(UTF_8)
+ support.write(InternalRow(UTF8String.fromBytes(bytes, 7, 5)))
+
+ val argument = ArgumentCaptor.forClass(classOf[Binary])
+ verify(consumer).addBinary(argument.capture())
+ val binary = argument.getValue
+ assert(binary.isBackingBytesReused)
+ assert(binary.toByteBuffer.array() eq bytes)
+ assert(binary.toStringUsingUTF8 == "value")
+ }
+
+ for {
+ storage <- Seq("array", "slice", "offheap")
+ dictionary <- Seq("off", "on", "fallback")
+ version <- ParquetProperties.WriterVersion.values()
+ } {
+ test(s"SPARK-60321: strings with reused $storage memory, " +
+ s"dictionary $dictionary, writer $version") {
+ val expected = reusedStringTestValues
+ val offHeap = storage == "offheap"
+ withTempPath { file =>
+ val conf = parquetStringWriterConf
+ val path = new Path(file.toURI)
Review Comment:
Thanks fixed
--
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]