Skip to content

Commit

Permalink
Move initialization of UnixTimeExprMeta to constructor:
Browse files Browse the repository at this point in the history
Fixes NVIDIA#5984.

Currently, `UnixTimeExprMeta` postpones part of the initialization of its state
to `tagExprForGpu()`. This leads to situations where an incompletely initialized
`UnixTimeExprMeta` object is exercised at runtime, such as in NVIDIA#5984.

This change moves the initialization to the constructor, leaving `tagExprForGpu()`
to deal only with tagging.

Signed-off-by: MithunR <mythrocks@gmail.com>
  • Loading branch information
mythrocks committed Jul 22, 2022
1 parent 1b27375 commit 0101417
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,19 +374,26 @@ abstract class UnixTimeExprMeta[A <: BinaryExpression with TimeZoneAwareExpressi
rule: DataFromReplacementRule)
extends BinaryExprMeta[A](expr, conf, parent, rule) {

var sparkFormat: String = _
var strfFormat: String = _
val optionalRightStringLit: Option[String] =
if (expr.right.dataType == StringType) {
extractStringLit(expr.right)
} else {
None
}

lazy val (sparkFormat, strfFormat): (String, String) =
optionalRightStringLit match {
case Some(rightLit) =>
(rightLit,
DateUtils.tagAndGetCudfFormat(this, rightLit,
expr.left.dataType == DataTypes.StringType))
case None => (null, null)
}

override def tagExprForGpu(): Unit = {
// Date and Timestamp work too
if (expr.right.dataType == StringType) {
extractStringLit(expr.right) match {
case Some(rightLit) =>
sparkFormat = rightLit
strfFormat = DateUtils.tagAndGetCudfFormat(this,
sparkFormat, expr.left.dataType == DataTypes.StringType)
case None =>
willNotWorkOnGpu("format has to be a string literal")
}
if (expr.right.dataType == StringType && optionalRightStringLit.isEmpty) {
willNotWorkOnGpu("format has to be a string literal")
}
}
}
Expand Down

0 comments on commit 0101417

Please sign in to comment.