flink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject [3/3] incubator-flink git commit: [Scala API] Case Class serializer can work with classes that cannot be instantiated empty
Date Wed, 26 Nov 2014 17:51:27 GMT
[Scala API] Case Class serializer can work with classes that cannot be instantiated empty


Project: http://git-wip-us.apache.org/repos/asf/incubator-flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-flink/commit/112b3a93
Tree: http://git-wip-us.apache.org/repos/asf/incubator-flink/tree/112b3a93
Diff: http://git-wip-us.apache.org/repos/asf/incubator-flink/diff/112b3a93

Branch: refs/heads/master
Commit: 112b3a937a1644982f24174163085c582b471f8c
Parents: 48b6d01
Author: Stephan Ewen <sewen@apache.org>
Authored: Wed Nov 26 17:23:00 2014 +0100
Committer: Stephan Ewen <sewen@apache.org>
Committed: Wed Nov 26 18:14:59 2014 +0100

----------------------------------------------------------------------
 .../scala/typeutils/CaseClassSerializer.scala   | 35 ++++++++++++--------
 1 file changed, 21 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-flink/blob/112b3a93/flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/CaseClassSerializer.scala
----------------------------------------------------------------------
diff --git a/flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/CaseClassSerializer.scala
b/flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/CaseClassSerializer.scala
index 61b876f..f82a67f 100644
--- a/flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/CaseClassSerializer.scala
+++ b/flink-scala/src/main/scala/org/apache/flink/api/scala/typeutils/CaseClassSerializer.scala
@@ -33,15 +33,29 @@ abstract class CaseClassSerializer[T <: Product](
 
   @transient var fields : Array[AnyRef] = _
   
+  @transient var instanceCreationFailed : Boolean = false
   
   def createInstance: T = {
-    initArray()
-    var i = 0
-    while (i < arity) {
-      fields(i) = fieldSerializers(i).createInstance()
-      i += 1
+    if (instanceCreationFailed) {
+      null.asInstanceOf[T]
+    }
+    else {
+      initArray()
+      try {
+        var i = 0
+        while (i < arity) {
+          fields(i) = fieldSerializers(i).createInstance()
+          i += 1
+        }
+        createInstance(fields)
+      }
+      catch {
+        case t: Throwable => {
+          instanceCreationFailed = true
+          null.asInstanceOf[T]
+        }
+      }
     }
-    createInstance(fields)
   }
 
   def copy(from: T, reuse: T): T = {
@@ -68,14 +82,7 @@ abstract class CaseClassSerializer[T <: Product](
   }
 
   def deserialize(reuse: T, source: DataInputView): T = {
-    initArray()
-    var i = 0
-    while (i < arity) {
-      val field = reuse.productElement(i).asInstanceOf[AnyRef]
-      fields(i) = fieldSerializers(i).deserialize(field, source)
-      i += 1
-    }
-    createInstance(fields)
+    deserialize(source);
   }
   
   def deserialize(source: DataInputView): T = {


Mime
View raw message