the-sakthi commented on code in PR #50336: URL: https://github.com/apache/spark/pull/50336#discussion_r2023835597
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala: ########## @@ -290,3 +291,63 @@ object HourExpressionBuilder extends ExpressionBuilder { } } } + +case class CurrentTime(precision: Int = 6) extends CurrentTimestampLike with ExpectsInputTypes { + // The function returns a TIME(n). + override def dataType: DataType = TimeType(precision) + + override def prettyName: String = "current_time" + + override def inputTypes: Seq[AbstractDataType] = Seq(IntegerType) + + override def checkInputDataTypes(): TypeCheckResult = { + if (precision < TimeType.MIN_PRECISION || precision > TimeType.MICROS_PRECISION) { + TypeCheckFailure(s"Invalid precision $precision. Must be between 0 and 6.") + } else { + TypeCheckSuccess + } + } +} + +/** + * Returns the current time at the start of query evaluation. + * There is no code generation since this expression should get constant folded by the optimizer. + */ +// scalastyle:off line.size.limit +@ExpressionDescription( + usage = """ + _FUNC_() - Returns the current time at the start of query evaluation. All calls of current_time within the same query return the same value. + + _FUNC_ - Returns the current time at the start of query evaluation. + """, + examples = """ + Examples: + > SELECT _FUNC_(); + 15:49:11.914120 + > SELECT _FUNC_; + 15:49:11.914120 + > SELECT _FUNC_(0); + 15:49:11 + > SELECT _FUNC_(3); + 15:49:11.914 + """, + group = "datetime_funcs", + since = "4.1.0") +// scalastyle:on line.size.limit +object CurrentTimeExpressionBuilder extends ExpressionBuilder { Review Comment: Makes sense! Rev 2 accordingly. -- 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. To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org