Skip to content

Commit 8bfd973

Browse files
committed
Fix serialization of MutablePair. Also provide an interface for easy updating.
1 parent 181b130 commit 8bfd973

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/src/main/scala/org/apache/spark/util/MutablePair.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,20 @@ package org.apache.spark.util
2525
* @param _2 Element 2 of this MutablePair
2626
*/
2727
case class MutablePair[@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T1,
28-
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
28+
@specialized(Int, Long, Double, Char, Boolean/*, AnyRef*/) T2]
2929
(var _1: T1, var _2: T2)
3030
extends Product2[T1, T2]
3131
{
32+
/** No-arg constructor for serialization */
33+
def this() = this(null.asInstanceOf[T1], null.asInstanceOf[T2])
34+
35+
/** Updates this pair with new values and returns itself */
36+
def apply(n1: T1, n2: T2): MutablePair[T1, T2] = {
37+
_1 = n1
38+
_2 = n2
39+
this
40+
}
41+
3242
override def toString = "(" + _1 + "," + _2 + ")"
3343

3444
override def canEqual(that: Any): Boolean = that.isInstanceOf[MutablePair[_,_]]

0 commit comments

Comments
 (0)