Github user mgaido91 commented on a diff in the pull request:
https://github.com/apache/spark/pull/21537#discussion_r194703775
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
---
@@ -1004,26 +1014,30 @@ case class Cast(child: Expression, dataType:
DataType, timeZoneId: Option[String
private[this] def castToIntervalCode(from: DataType): CastFunction =
from match {
case StringType =>
(c, evPrim, evNull) =>
- s"""$evPrim = CalendarInterval.fromString($c.toString());
+ code"""$evPrim = CalendarInterval.fromString($c.toString());
if(${evPrim} == null) {
${evNull} = true;
}
""".stripMargin
}
- private[this] def decimalToTimestampCode(d: String): String =
- s"($d.toBigDecimal().bigDecimal().multiply(new
java.math.BigDecimal(1000000L))).longValue()"
- private[this] def longToTimeStampCode(l: String): String = s"$l *
1000000L"
- private[this] def timestampToIntegerCode(ts: String): String =
- s"java.lang.Math.floor((double) $ts / 1000000L)"
- private[this] def timestampToDoubleCode(ts: String): String = s"$ts /
1000000.0"
+ private[this] def decimalToTimestampCode(d: ExprValue): ExprValue =
+ JavaCode.expression(
+ s"($d.toBigDecimal().bigDecimal().multiply(new
java.math.BigDecimal(1000000L))).longValue()",
--- End diff --
is it safe to do this? aren't we loosing the reference to `$d`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]