Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,21 @@ object HourExpressionBuilder extends ExpressionBuilder {
case class SecondsOfTimeWithFraction(child: Expression)
extends RuntimeReplaceable
with ExpectsInputTypes {

override def replacement: Expression = {

val precision = child.dataType match {
case TimeType(p) => p
case _ => TimeType.MIN_PRECISION
}
StaticInvoke(
classOf[DateTimeUtils.type],
DecimalType(8, 6),
"getSecondsOfTimeWithFraction",
Seq(child, Literal(precision)),
Seq(child.dataType, IntegerType))
}
private val precision: Int = child.dataType.asInstanceOf[TimeType].precision
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This val is initialized before the invoke of inputTypes(), so, asInstanceOf[TimeType] can fail on other types.


override def inputTypes: Seq[AbstractDataType] =
Seq(TimeType(precision))
Seq(TypeCollection(TimeType.MIN_PRECISION to TimeType.MAX_PRECISION map TimeType.apply: _*))

override def children: Seq[Expression] = Seq(child)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,8 @@ class TimeExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
checkEvaluation(
SecondsOfTimeWithFraction(Literal.create(null, TimeType(TimeType.MICROS_PRECISION))),
null)
assert(SecondsOfTimeWithFraction(Literal.create(null)).inputTypes.nonEmpty)

checkConsistencyBetweenInterpretedAndCodegen(
(child: Expression) => SecondsOfTimeWithFraction(child).replacement,
TimeType())
Expand Down