@@ -32,6 +32,7 @@ import com.esotericsoftware.kryo.serializers.JavaSerializer
32
32
import com .google .protobuf .Message
33
33
import com .twitter .chill .protobuf .ProtobufSerializer
34
34
import org .apache .spark .serializer .KryoRegistrator
35
+ import org .slf4j .LoggerFactory
35
36
36
37
/**
37
38
* NOTE: PLEASE READ CAREFULLY BEFORE CHANGING
@@ -50,6 +51,8 @@ import org.apache.spark.serializer.KryoRegistrator
50
51
* </ol>
51
52
*/
52
53
class HoodieSparkKryoRegistrar extends HoodieCommonKryoRegistrar with KryoRegistrator {
54
+ private val log = LoggerFactory .getLogger(classOf [HoodieSparkKryoRegistrar ])
55
+
53
56
54
57
override def registerClasses (kryo : Kryo ): Unit = {
55
58
// /////////////////////////////////////////////////////////////////////////
@@ -74,7 +77,14 @@ class HoodieSparkKryoRegistrar extends HoodieCommonKryoRegistrar with KryoRegist
74
77
// So we replace it with [[HadoopStorageConfiguration]] for Spark.
75
78
kryo.register(classOf [HadoopStorageConfiguration ], new JavaSerializer ())
76
79
// NOTE: Protobuf objects are not serializable by default using kryo, need to register them explicitly.
77
- kryo.addDefaultSerializer(classOf [Message ], new ProtobufSerializer ())
80
+ // Only initialize this serializer if Protobuf is on the classpath.
81
+ try {
82
+ if (Class .forName(classOf [Message ].getName, false , getClass.getClassLoader) != null ) {
83
+ kryo.addDefaultSerializer(classOf [Message ], new ProtobufSerializer ())
84
+ }
85
+ } catch {
86
+ case _ : ClassNotFoundException | _ : NoClassDefFoundError => log.warn(" Protobuf classes not found on the classpath, skipping Protobuf serializer registration." )
87
+ }
78
88
}
79
89
80
90
/**
0 commit comments