Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19797#discussion_r152719475
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
@@ -799,9 +799,11 @@ case class Cast(child: Expression, dataType: DataType,
timeZoneId: Option[String
private[this] def castToByteCode(from: DataType, ctx: CodegenContext):
CastFunction = from match {
case StringType =>
- val wrapper = ctx.freshName("wrapper")
- ctx.addMutableState("UTF8String.IntWrapper", wrapper,
- s"$wrapper = new UTF8String.IntWrapper();")
+ val wrapper = "intWrapper"
+ if (!ctx.mutableStates.exists(s => s._1 == wrapper)) {
+ ctx.addMutableState("UTF8String.IntWrapper", wrapper,
+ s"$wrapper = new UTF8String.IntWrapper();")
+ }
--- End diff --
Add a help method to `CodegenContext`? Like `reuseOrAddMutableState`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]