LuciferYang commented on code in PR #39148:
URL: https://github.com/apache/spark/pull/39148#discussion_r1054012625


##########
core/src/main/scala/org/apache/spark/status/protobuf/KVStoreProtobufSerializer.scala:
##########
@@ -17,39 +17,33 @@
 
 package org.apache.spark.status.protobuf
 
-import org.apache.spark.status._
+import java.util.ServiceLoader
+
+import collection.JavaConverters._
+
 import org.apache.spark.status.KVUtils.KVStoreScalaSerializer
 
 private[spark] class KVStoreProtobufSerializer extends KVStoreScalaSerializer {
-  override def serialize(o: Object): Array[Byte] = o match {
-    case j: JobDataWrapper => JobDataWrapperSerializer.
-      serialize(j)
-    case t: TaskDataWrapper => TaskDataWrapperSerializer.serialize(t)
-    case e: ExecutorStageSummaryWrapper => 
ExecutorStageSummaryWrapperSerializer.serialize(e)
-    case a: ApplicationEnvironmentInfoWrapper =>
-      ApplicationEnvironmentInfoWrapperSerializer.serialize(a)
-    case a: ApplicationInfoWrapper => 
ApplicationInfoWrapperSerializer.serialize(a)
-    case r: RDDStorageInfoWrapper =>
-      RDDStorageInfoWrapperSerializer.serialize(r)
-    case r: ResourceProfileWrapper => 
ResourceProfileWrapperSerializer.serialize(r)
-    case other => super.serialize(other)
-  }
-
-  override def deserialize[T](data: Array[Byte], klass: Class[T]): T = klass 
match {
-    case _ if classOf[JobDataWrapper].isAssignableFrom(klass) =>
-      JobDataWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if classOf[TaskDataWrapper].isAssignableFrom(klass) =>
-      TaskDataWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if classOf[ExecutorStageSummaryWrapper].isAssignableFrom(klass) =>
-      ExecutorStageSummaryWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if 
classOf[ApplicationEnvironmentInfoWrapper].isAssignableFrom(klass) =>
-      
ApplicationEnvironmentInfoWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if classOf[ApplicationInfoWrapper].isAssignableFrom(klass) =>
-      ApplicationInfoWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if classOf[RDDStorageInfoWrapper].isAssignableFrom(klass) =>
-      RDDStorageInfoWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case _ if classOf[ResourceProfileWrapper].isAssignableFrom(klass) =>
-      ResourceProfileWrapperSerializer.deserialize(data).asInstanceOf[T]
-    case other => super.deserialize(data, klass)
-  }
+  override def serialize(o: Object): Array[Byte] =
+    KVStoreProtobufSerializer.getSerializer(o.getClass) match {
+      case Some(serializer) => serializer.serialize(o)

Review Comment:
   If ProtoBufSerDe is defined as
   
   ```scala
   trait ProtoBufSerDe[T] {
   
     def serialize(input: T): Array[Byte]
   
     def deserialize(bytes: Array[Byte]): T
   }
   ```
   
   What datatype should `o` be `asInstanceOf` at line 29? `o` still an Object, 
I really didn't think clearly
   @gengliangwang @techaddict



-- 
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]

Reply via email to