maropu commented on a change in pull request #25708: [SPARK-28141][SQL] Support
special date values
URL: https://github.com/apache/spark/pull/25708#discussion_r321988152
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
##########
@@ -1056,28 +1056,35 @@ case class Cast(child: Expression, dataType: DataType,
timeZoneId: Option[String
private[this] def castToDateCode(
from: DataType,
- ctx: CodegenContext): CastFunction = from match {
- case StringType =>
- val intOpt = ctx.freshVariable("intOpt", classOf[Option[Integer]])
- (c, evPrim, evNull) => code"""
- scala.Option<Integer> $intOpt =
- org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToDate($c);
- if ($intOpt.isDefined()) {
- $evPrim = ((Integer) $intOpt.get()).intValue();
- } else {
- $evNull = true;
- }
- """
- case TimestampType =>
+ ctx: CodegenContext): CastFunction = {
+ def getZoneId() = {
val zoneIdClass = classOf[ZoneId]
- val zid = JavaCode.global(
+ JavaCode.global(
ctx.addReferenceObj("zoneId", zoneId, zoneIdClass.getName),
zoneIdClass)
- (c, evPrim, evNull) =>
- code"""$evPrim =
-
org.apache.spark.sql.catalyst.util.DateTimeUtils.microsToEpochDays($c, $zid);"""
- case _ =>
- (c, evPrim, evNull) => code"$evNull = true;"
+ }
+ from match {
+ case StringType =>
+ val intOpt = ctx.freshVariable("intOpt", classOf[Option[Integer]])
+ val zid = getZoneId()
+ (c, evPrim, evNull) =>
+ code"""
+ scala.Option<Integer> $intOpt =
+ org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToDate($c,
$zid);
+ if ($intOpt.isDefined()) {
+ $evPrim = ((Integer) $intOpt.get()).intValue();
+ } else {
+ $evNull = true;
+ }
+ """
+ case TimestampType =>
+ val zid = getZoneId()
+ (c, evPrim, evNull) =>
+ code"""$evPrim =
+
org.apache.spark.sql.catalyst.util.DateTimeUtils.microsToEpochDays($c, $zid);"""
+ case _ =>
+ (c, evPrim, evNull) => code"$evNull = true;"
+ }
}
Review comment:
Just put the gen'd code for other reviewers;
```
/* 051 */ boolean project_isNull_0 = columnartorow_isNull_0;
/* 052 */ int project_value_0 = -1;
/* 053 */ if (!columnartorow_isNull_0) {
/* 054 */ scala.Option<Integer> project_intOpt_0 =
/* 055 */
org.apache.spark.sql.catalyst.util.DateTimeUtils.stringToDate(columnartorow_value_0,
((java.time.ZoneId) references[2] /* zoneId */));
/* 056 */ if (project_intOpt_0.isDefined()) {
/* 057 */ project_value_0 = ((Integer)
project_intOpt_0.get()).intValue();
/* 058 */ } else {
/* 059 */ project_isNull_0 = true;
/* 060 */ }
/* 061 */ }
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]