From 149910111331133d52e0cb01b256f7f731b436ad Mon Sep 17 00:00:00 2001 From: Prashant Sharma Date: Thu, 31 Jul 2014 22:57:13 -0700 Subject: SPARK-2632, SPARK-2576. Fixed by only importing what is necessary during class definition. Without this patch, it imports everything available in the scope. ```scala scala> val a = 10l val a = 10l a: Long = 10 scala> import a._ import a._ import a._ scala> case class A(a: Int) // show case class A(a: Int) // show class $read extends Serializable { def () = { super.; () }; class $iwC extends Serializable { def () = { super.; () }; class $iwC extends Serializable { def () = { super.; () }; import org.apache.spark.SparkContext._; class $iwC extends Serializable { def () = { super.; () }; val $VAL5 = $line5.$read.INSTANCE; import $VAL5.$iw.$iw.$iw.$iw.a; class $iwC extends Serializable { def () = { super.; () }; import a._; class $iwC extends Serializable { def () = { super.; () }; class $iwC extends Serializable { def () = { super.; () }; case class A extends scala.Product with scala.Serializable { val a: Int = _; def (a: Int) = { super.; () } } }; val $iw = new $iwC. }; val $iw = new $iwC. }; val $iw = new $iwC. }; val $iw = new $iwC. }; val $iw = new $iwC. }; val $iw = new $iwC. } object $read extends scala.AnyRef { def () = { super.; () }; val INSTANCE = new $read. } defined class A ``` With this patch, it just imports only the necessary. ```scala scala> val a = 10l val a = 10l a: Long = 10 scala> import a._ import a._ import a._ scala> case class A(a: Int) // show case class A(a: Int) // show class $read extends Serializable { def () = { super.; () }; class $iwC extends Serializable { def () = { super.; () }; class $iwC extends Serializable { def () = { super.; () }; case class A extends scala.Product with scala.Serializable { val a: Int = _; def (a: Int) = { super.; () } } }; val $iw = new $iwC. }; val $iw = new $iwC. } object $read extends scala.AnyRef { def () = { super.; () }; val INSTANCE = new $read. } defined class A scala> ``` This patch also adds a `:fallback` mode on being enabled it will restore the spark-shell's 1.0.0 behaviour. Author: Prashant Sharma Author: Yin Huai Author: Prashant Sharma Closes #1635 from ScrapCodes/repl-fix-necessary-imports and squashes the following commits: b1968d2 [Prashant Sharma] Added toschemaRDD to test case. 0b712bb [Yin Huai] Add a REPL test to test importing a method. 02ad8ff [Yin Huai] Add a REPL test for importing SQLContext.createSchemaRDD. ed6d0c7 [Prashant Sharma] Added a fallback mode, incase users run into issues while using repl. b63d3b2 [Prashant Sharma] SPARK-2632, SPARK-2576. Fixed by only importing what is necessary during class definition. --- .../scala/org/apache/spark/repl/ReplSuite.scala | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'repl/src/test/scala/org') diff --git a/repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala b/repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala index e2d8d5ff38..c8763eb277 100644 --- a/repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala +++ b/repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala @@ -256,6 +256,33 @@ class ReplSuite extends FunSuite { assertDoesNotContain("error:", output) assertDoesNotContain("Exception", output) } + + test("SPARK-2576 importing SQLContext.createSchemaRDD.") { + // We need to use local-cluster to test this case. + val output = runInterpreter("local-cluster[1,1,512]", + """ + |val sqlContext = new org.apache.spark.sql.SQLContext(sc) + |import sqlContext.createSchemaRDD + |case class TestCaseClass(value: Int) + |sc.parallelize(1 to 10).map(x => TestCaseClass(x)).toSchemaRDD.collect + """.stripMargin) + assertDoesNotContain("error:", output) + assertDoesNotContain("Exception", output) + } + + test("SPARK-2632 importing a method from non serializable class and not using it.") { + val output = runInterpreter("local", + """ + |class TestClass() { def testMethod = 3 } + |val t = new TestClass + |import t.testMethod + |case class TestCaseClass(value: Int) + |sc.parallelize(1 to 10).map(x => TestCaseClass(x)).collect + """.stripMargin) + assertDoesNotContain("error:", output) + assertDoesNotContain("Exception", output) + } + if (System.getenv("MESOS_NATIVE_LIBRARY") != null) { test("running on Mesos") { val output = runInterpreter("localquiet", -- cgit v1.2.3