forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced KryoSerializer with an updated SparkSqlSerializer
* SparkSqlSerializer is moved to a separate source file * SparkSqlSerializer.newKryo calls super.newKryo * Class registration is no longer required, since we may de/serialise objects of any class with generic column accessor/builder. Signed-off-by: Cheng Lian <[email protected]>
- Loading branch information
Showing
7 changed files
with
67 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 0 additions & 22 deletions
22
sql/core/src/main/scala/org/apache/spark/sql/execution/KryoSerializer.scala
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlSerializer.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.apache.spark.sql | ||
package execution | ||
|
||
import java.nio.ByteBuffer | ||
|
||
import com.esotericsoftware.kryo.io.{Input, Output} | ||
import com.esotericsoftware.kryo.{Serializer, Kryo} | ||
|
||
import org.apache.spark.{SparkEnv, SparkConf} | ||
import org.apache.spark.serializer.KryoSerializer | ||
import org.apache.spark.util.MutablePair | ||
|
||
class SparkSqlSerializer(conf: SparkConf) extends KryoSerializer(conf) { | ||
override def newKryo(): Kryo = { | ||
val kryo = super.newKryo() | ||
kryo.setRegistrationRequired(false) | ||
kryo.register(classOf[MutablePair[_,_]]) | ||
kryo.register(classOf[Array[Any]]) | ||
kryo.register(classOf[org.apache.spark.sql.catalyst.expressions.GenericRow]) | ||
kryo.register(classOf[org.apache.spark.sql.catalyst.expressions.GenericMutableRow]) | ||
kryo.register(classOf[scala.collection.mutable.ArrayBuffer[_]]) | ||
kryo.register(classOf[scala.math.BigDecimal], new BigDecimalSerializer) | ||
kryo.setReferences(false) | ||
kryo.setClassLoader(this.getClass.getClassLoader) | ||
kryo | ||
} | ||
} | ||
|
||
object SparkSqlSerializer { | ||
@transient lazy val ser: SparkSqlSerializer = { | ||
val sparkConf = Option(SparkEnv.get).map(_.conf).getOrElse(new SparkConf()) | ||
new SparkSqlSerializer(sparkConf) | ||
} | ||
|
||
def serialize[T](o: T): Array[Byte] = { | ||
ser.newInstance().serialize(o).array() | ||
} | ||
|
||
def deserialize[T](bytes: Array[Byte]): T = { | ||
ser.newInstance().deserialize[T](ByteBuffer.wrap(bytes)) | ||
} | ||
} | ||
|
||
class BigDecimalSerializer extends Serializer[BigDecimal] { | ||
def write(kryo: Kryo, output: Output, bd: math.BigDecimal) { | ||
// TODO: There are probably more efficient representations than strings... | ||
output.writeString(bd.toString()) | ||
} | ||
|
||
def read(kryo: Kryo, input: Input, tpe: Class[BigDecimal]): BigDecimal = { | ||
BigDecimal(input.readString()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters