Skip to content

Commit 080e983

Browse files
committed
Modified test
1 parent d3fc82d commit 080e983

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

mllib/src/main/scala/org/apache/spark/ml/param/params.scala

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,10 +863,7 @@ final class ParamMap private[ml] (private val map: mutable.Map[Param[Any], Any])
863863
// returns the instance of collections.Map, not mutable.Map.
864864
// Otherwise, we get ClassCastException.
865865
// Not using filterKeys also avoid SI-6654
866-
val filtered = map.filter {
867-
case (k, _) =>
868-
k.parent == parent.uid
869-
}
866+
val filtered = map.filter { case (k, _) => k.parent == parent.uid }
870867
new ParamMap(filtered)
871868
}
872869

mllib/src/test/scala/org/apache/spark/ml/param/ParamsSuite.scala

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.ml.param
1919

20+
import java.io.{ByteArrayOutputStream, NotSerializableException, ObjectOutputStream}
21+
2022
import org.apache.spark.SparkFunSuite
2123
import org.apache.spark.ml.util.MyParams
2224
import org.apache.spark.mllib.linalg.{Vector, Vectors}
@@ -367,8 +369,23 @@ class ParamsSuite extends SparkFunSuite {
367369
assert(p.parent === params1.uid)
368370
}
369371

370-
// Following assertion is to avoid SI-6654
371-
assert(filteredParamMap.isInstanceOf[Serializable])
372+
// At the previous implementation of ParamMap#filter,
373+
// mutable.Map#filterKeys was used internally but
374+
// the return type of the method is not serializable (see SI-6654).
375+
// Now mutable.Map#filter is used instead of filterKeys and the return type is serializable.
376+
// So let's ensure serializability.
377+
val objOut = new ObjectOutputStream(new ByteArrayOutputStream())
378+
try {
379+
objOut.writeObject(filteredParamMap)
380+
} catch {
381+
case _: NotSerializableException =>
382+
fail("The field of ParamMap 'map' may not be serializable. " +
383+
"See SI-6654 and the implementation of ParamMap#filter")
384+
case e: Exception =>
385+
fail(s"Exception was thrown unexpectedly during the serializability test: ${e.getMessage}")
386+
} finally {
387+
objOut.close()
388+
}
372389
}
373390
}
374391

0 commit comments

Comments
 (0)