Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -575,10 +575,10 @@ class CodegenContext {
if (freshNameIds.contains(fullName)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now we don't need this if

val id = freshNameIds.getOrElse(fullName, 0)
val res = s"${fullName}_$id"
freshNameIds(fullName) = id + 1
res

val id = freshNameIds(fullName)
freshNameIds(fullName) = id + 1
s"$fullName$id"
s"${fullName}_$id"
} else {
freshNameIds += fullName -> 1
fullName
s"${fullName}_0"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,14 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(!ctx.subExprEliminationExprs.contains(ref))
}
}

test("SPARK-23986: freshName can generate duplicated names") {
val ctx = new CodegenContext
val names1 = ctx.freshName("myName1") :: ctx.freshName("myName1") ::
ctx.freshName("myName11") :: Nil
assert(names1.distinct.length == 3)
val names2 = ctx.freshName("a") :: ctx.freshName("a") ::
ctx.freshName("a_1") :: ctx.freshName("a_0") :: Nil
assert(names2.distinct.length == 4)
}
}