MaxGekk commented on code in PR #50296: URL: https://github.com/apache/spark/pull/50296#discussion_r2006853665
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala: ########## @@ -120,3 +122,52 @@ case class ToTimeParser(fmt: Option[String]) { } } } + +case class MinutesOfTime(child: Expression) + extends RuntimeReplaceable + with ExpectsInputTypes { + + override def replacement: Expression = StaticInvoke( + classOf[DateTimeUtils.type], + IntegerType, + "getMinutesOfTime", + Seq(child), + Seq(child.dataType) + ) + + override def inputTypes: Seq[AbstractDataType] = Seq(TimeType()) + + override def children: Seq[Expression] = Seq(child) + + override def prettyName: String = "minute" + + override protected def withNewChildrenInternal( + newChildren: IndexedSeq[Expression]): Expression = { + copy(child = newChildren.head) + } +} + +// scalastyle:off line.size.limit +@ExpressionDescription( + usage = """ + _FUNC_(time_expr) - Returns the minute component of the given time. + """, + examples = """ + Examples: + > SELECT _FUNC_(TIME'23:59:59.999999'); + 59 + """, + since = "4.1.0", + group = "datetime_funcs") +// scalastyle:on line.size.limit +object MinuteExpressionBuilder extends ExpressionBuilder { + override def build(name: String, expressions: Seq[Expression]): Expression = { + val child = expressions.head Review Comment: Please, handle empty `expressions`. For now, it fails with: ```sql spark-sql (default)> SELECT minute(); 25/03/21 07:56:16 ERROR SparkSQLDriver: Failed in [SELECT minute()] java.util.NoSuchElementException: head of empty list at scala.collection.immutable.Nil$.head(List.scala:663) at scala.collection.immutable.Nil$.head(List.scala:662) at org.apache.spark.sql.catalyst.expressions.MinuteExpressionBuilder$.build(timeExpressions.scala:165) ``` -- 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