@@ -338,7 +338,17 @@ class ArrayFeature[TValue: ClassTag](model: HasFeatures, override val name: Stri
338338 val fs : FileSystem = FileSystem .get(uri, spark.sparkContext.hadoopConfiguration)
339339 val dataPath = getFieldPath(path, field)
340340 if (fs.exists(dataPath)) {
341- Some (spark.sparkContext.objectFile[TValue ](dataPath.toString).collect())
341+ try {
342+ Some (spark.sparkContext.objectFile[TValue ](dataPath.toString).collect())
343+ } catch {
344+ case e : org.apache.spark.SparkException
345+ if e.getCause.isInstanceOf [java.io.InvalidClassException ] =>
346+ println(
347+ " WARNING: Detected InvalidClassException during deserialization, attempting to load as legacy object." )
348+ Some (deserializeLegacyObject[TValue ](spark, dataPath.toString).collect())
349+ case e : Exception =>
350+ throw e
351+ }
342352 } else {
343353 None
344354 }
@@ -391,7 +401,17 @@ class SetFeature[TValue: ClassTag](model: HasFeatures, override val name: String
391401 val fs : FileSystem = FileSystem .get(uri, spark.sparkContext.hadoopConfiguration)
392402 val dataPath = getFieldPath(path, field)
393403 if (fs.exists(dataPath)) {
394- Some (spark.sparkContext.objectFile[TValue ](dataPath.toString).collect().toSet)
404+ try {
405+ Some (spark.sparkContext.objectFile[TValue ](dataPath.toString).collect.toSet)
406+ } catch {
407+ case e : org.apache.spark.SparkException
408+ if e.getCause.isInstanceOf [java.io.InvalidClassException ] =>
409+ println(
410+ " WARNING: Detected InvalidClassException during deserialization, attempting to load as legacy object." )
411+ Some (deserializeLegacyObject[TValue ](spark, dataPath.toString).collect.toSet)
412+ case e : Exception =>
413+ throw e
414+ }
395415 } else {
396416 None
397417 }
@@ -444,8 +464,17 @@ class TransducerFeature(model: HasFeatures, override val name: String)
444464 val fs : FileSystem = FileSystem .get(uri, spark.sparkContext.hadoopConfiguration)
445465 val dataPath = getFieldPath(path, field)
446466 if (fs.exists(dataPath)) {
447- val sc = spark.sparkContext.objectFile[VocabParser ](dataPath.toString).collect().head
448- Some (sc)
467+ try {
468+ Some (spark.sparkContext.objectFile[VocabParser ](dataPath.toString).collect().head)
469+ } catch {
470+ case e : org.apache.spark.SparkException
471+ if e.getCause.isInstanceOf [java.io.InvalidClassException ] =>
472+ println(
473+ " WARNING: Detected InvalidClassException during deserialization, attempting to load as legacy object." )
474+ Some (deserializeLegacyObject[VocabParser ](spark, dataPath.toString).collect().head)
475+ case e : Exception =>
476+ throw e
477+ }
449478 } else {
450479 None
451480 }
0 commit comments