Skip to content

Commit 81fec99

Browse files
ScrapCodespwendell
authored andcommitted
[SPARK-2452] Create a new valid for each instead of using lineId.
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.
1 parent 5d16d5b commit 81fec99

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

repl/src/main/scala/org/apache/spark/repl/SparkImports.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ trait SparkImports {
197197
for (imv <- x.definedNames) {
198198
if (currentImps contains imv) addWrapper()
199199
val objName = req.lineRep.readPath
200-
val valName = "$VAL" + req.lineRep.lineId
200+
val valName = "$VAL" + newValId()
201201

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

225+
private var curValId = 0
226+
227+
private def newValId(): Int = {
228+
curValId += 1
229+
curValId
230+
}
225231
}

repl/src/test/scala/org/apache/spark/repl/ReplSuite.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ class ReplSuite extends FunSuite {
235235
assertContains("res4: Array[Int] = Array(0, 0, 0, 0, 0)", output)
236236
}
237237

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

250+
test("SPARK-2452 compound statements.") {
251+
val output = runInterpreter("local",
252+
"""
253+
|val x = 4 ; def f() = x
254+
|f()
255+
""".stripMargin)
256+
assertDoesNotContain("error:", output)
257+
assertDoesNotContain("Exception", output)
258+
}
250259
if (System.getenv("MESOS_NATIVE_LIBRARY") != null) {
251260
test("running on Mesos") {
252261
val output = runInterpreter("localquiet",

0 commit comments

Comments
 (0)