alexeykudinkin commented on code in PR #7014:
URL: https://github.com/apache/hudi/pull/7014#discussion_r1001049665
##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/spark/sql/hudi/SerDeUtils.scala:
##########
@@ -17,39 +17,29 @@
package org.apache.spark.sql.hudi
-import java.io.ByteArrayOutputStream
-
-import com.esotericsoftware.kryo.Kryo
-import com.esotericsoftware.kryo.io.{Input, Output}
import org.apache.spark.SparkConf
-import org.apache.spark.serializer.KryoSerializer
+import org.apache.spark.serializer.{KryoSerializer, SerializerInstance}
+
+import java.nio.ByteBuffer
object SerDeUtils {
- private val kryoLocal = new ThreadLocal[Kryo] {
+ private val SERIALIZER_THREAD_LOCAL = new ThreadLocal[SerializerInstance] {
- override protected def initialValue: Kryo = {
- val serializer = new KryoSerializer(new SparkConf(true))
- serializer.newKryo()
+ override protected def initialValue: SerializerInstance = {
+ new KryoSerializer(new SparkConf(true)).newInstance()
}
}
def toBytes(o: Any): Array[Byte] = {
- val outputStream = new ByteArrayOutputStream(4096 * 5)
- val output = new Output(outputStream)
- try {
- kryoLocal.get.writeClassAndObject(output, o)
- output.flush()
- } finally {
- output.clear()
- output.close()
- }
- outputStream.toByteArray
+ val bb: ByteBuffer = SERIALIZER_THREAD_LOCAL.get.serialize(o)
+ val bytes = new Array[Byte](bb.capacity())
Review Comment:
Should actually be `remaining`
--
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]