This repository has been archived by the owner on Feb 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from scala/support-for-transient
Adds ability to pickle/unpickle things marked @transient
- Loading branch information
Showing
6 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package scala.pickling.implicitparams | ||
|
||
import org.scalatest.FunSuite | ||
import scala.pickling._ | ||
import json._ | ||
|
||
|
||
case class Person(implicit name: String, age: Int) | ||
object Test { | ||
class SimpleImplParamTest extends FunSuite { | ||
test("main") { | ||
implicit val nme = "Harry" | ||
implicit val age = 18 | ||
|
||
val per = Person() | ||
val p = per.pickle | ||
val up = p.unpickle[Person] | ||
assert(per == up) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package scala.pickling.transienttest | ||
|
||
import org.scalatest.FunSuite | ||
import scala.reflect.ClassTag | ||
import scala.pickling._ | ||
import json._ | ||
|
||
case class Person(val name: String , @transient val ssNumber: Int) { | ||
override def toString = s"Person($name)" | ||
} | ||
|
||
class Dependency[T] | ||
|
||
class SparkConf(loadDefaults: Boolean) | ||
class SparkContext(config: SparkConf) | ||
|
||
class RDD[T: ClassTag]( | ||
@transient private var sc: SparkContext, | ||
@transient private var deps: Seq[Dependency[_]] | ||
) | ||
|
||
class RangePartitioner[K : ClassTag, V]( | ||
@transient val partitions: Int, | ||
@transient val rdd: RDD[_ <: Product2[K,V]], | ||
private var ascending: Boolean = true) { | ||
override def toString = s"RangePartitioner(ascending = $ascending)" | ||
} | ||
|
||
class TransientSimpleTest extends FunSuite { | ||
test("main") { | ||
val per = Person("Jenny", 123) | ||
val p: JSONPickle = per.pickle | ||
val up = p.unpickle[Person] | ||
assert(up.ssNumber == 0) | ||
assert(per.toString == up.toString) | ||
} | ||
} | ||
|
||
class TransientSparkTest extends FunSuite { | ||
test("main") { | ||
val sc = new SparkContext(new SparkConf(true)) | ||
val rdd = new RDD[(Int, Int)](sc, Seq(new Dependency())) | ||
val rp = new RangePartitioner[Int, Int](2, rdd) | ||
val p: JSONPickle = rp.pickle | ||
val up = p.unpickle[RangePartitioner[Int, Int]] | ||
assert(rp.toString == up.toString) | ||
} | ||
} | ||
|