Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/spark/pull/21537#discussion_r195333092
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
@@ -805,43 +811,43 @@ case class Cast(child: Expression, dataType:
DataType, timeZoneId: Option[String
private[this] def castToStringCode(from: DataType, ctx: CodegenContext):
CastFunction = {
from match {
case BinaryType =>
- (c, evPrim, evNull) => s"$evPrim = UTF8String.fromBytes($c);"
+ (c, evPrim, evNull) => code"$evPrim = UTF8String.fromBytes($c);"
case DateType =>
- (c, evPrim, evNull) => s"""$evPrim = UTF8String.fromString(
+ (c, evPrim, evNull) => code"""$evPrim = UTF8String.fromString(
org.apache.spark.sql.catalyst.util.DateTimeUtils.dateToString($c));"""
case TimestampType =>
- val tz = ctx.addReferenceObj("timeZone", timeZone)
- (c, evPrim, evNull) => s"""$evPrim = UTF8String.fromString(
+ val tz = JavaCode.global(ctx.addReferenceObj("timeZone",
timeZone), timeZone.getClass)
+ (c, evPrim, evNull) => code"""$evPrim = UTF8String.fromString(
org.apache.spark.sql.catalyst.util.DateTimeUtils.timestampToString($c, $tz));"""
case ArrayType(et, _) =>
(c, evPrim, evNull) => {
- val buffer = ctx.freshName("buffer")
- val bufferClass = classOf[UTF8StringBuilder].getName
+ val buffer = ctx.freshVariable("buffer",
classOf[UTF8StringBuilder])
+ val bufferClass = JavaCode.className(classOf[UTF8StringBuilder])
--- End diff --
I think we could add a class `Variable` which `GlobalVariable` and
`LocalVariable` inherit from having a `declare` method taking an optional
parameter `initialValue` so we can just invoke it to declare each variable. But
maybe this can also be a followup. What do you think?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]