Skip to content

[SPARK-51419][SQL][FOLLOWUP] Making hour function to accept any precision of TIME type #50554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
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 @@ -246,7 +246,8 @@ case class HoursOfTime(child: Expression)
Seq(child.dataType)
)

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,18 @@ class TimeExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
assert(builtExprForTime.isInstanceOf[HoursOfTime])
assert(builtExprForTime.asInstanceOf[HoursOfTime].child eq timeExpr)

assert(builtExprForTime.checkInputDataTypes().isSuccess)

// test TIME-typed child should build HoursOfTime for all allowed custom precision values
(TimeType.MIN_PRECISION to TimeType.MICROS_PRECISION).foreach { precision =>
val timeExpr = Literal(localTime(12, 58, 59), TimeType(precision))
val builtExpr = HourExpressionBuilder.build("hour", Seq(timeExpr))

assert(builtExpr.isInstanceOf[HoursOfTime])
assert(builtExpr.asInstanceOf[HoursOfTime].child eq timeExpr)
assert(builtExpr.checkInputDataTypes().isSuccess)
}

// test non TIME-typed child should build hour
val tsExpr = Literal("2007-09-03 10:45:23")
val builtExprForTs = HourExpressionBuilder.build("hour", Seq(tsExpr))
Expand Down