Skip to content

Commit

Permalink
[SPARK-2452] Create a new valid for each instead of using lineId.
Browse files Browse the repository at this point in the history
Author: Prashant Sharma <prashant@apache.org>

Closes apache#1441 from ScrapCodes/SPARK-2452/multi-statement and squashes the following commits:

26c5c72 [Prashant Sharma] Added a test case.
7e8d28d [Prashant Sharma] SPARK-2452, create a new valid for each  instead of using lineId, because Line ids can be same sometimes.
  • Loading branch information
ScrapCodes authored and pwendell committed Jul 22, 2014
1 parent 5d16d5b commit 81fec99
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 7 additions & 1 deletion repl/src/main/scala/org/apache/spark/repl/SparkImports.scala
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ trait SparkImports {
for (imv <- x.definedNames) {
if (currentImps contains imv) addWrapper()
val objName = req.lineRep.readPath
val valName = "$VAL" + req.lineRep.lineId
val valName = "$VAL" + newValId()

if(!code.toString.endsWith(".`" + imv + "`;\n")) { // Which means already imported
code.append("val " + valName + " = " + objName + ".INSTANCE;\n")
Expand All @@ -222,4 +222,10 @@ trait SparkImports {
private def membersAtPickler(sym: Symbol): List[Symbol] =
beforePickler(sym.info.nonPrivateMembers.toList)

private var curValId = 0

private def newValId(): Int = {
curValId += 1
curValId
}
}
11 changes: 10 additions & 1 deletion repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ReplSuite extends FunSuite {
assertContains("res4: Array[Int] = Array(0, 0, 0, 0, 0)", output)
}

test("SPARK-1199-simple-reproduce") {
test("SPARK-1199 two instances of same class don't type check.") {
val output = runInterpreter("local-cluster[1,1,512]",
"""
|case class Sum(exp: String, exp2: String)
Expand All @@ -247,6 +247,15 @@ class ReplSuite extends FunSuite {
assertDoesNotContain("Exception", output)
}

test("SPARK-2452 compound statements.") {
val output = runInterpreter("local",
"""
|val x = 4 ; def f() = x
|f()
""".stripMargin)
assertDoesNotContain("error:", output)
assertDoesNotContain("Exception", output)
}
if (System.getenv("MESOS_NATIVE_LIBRARY") != null) {
test("running on Mesos") {
val output = runInterpreter("localquiet",
Expand Down

0 comments on commit 81fec99

Please sign in to comment.