This is an automated email from the ASF dual-hosted git repository.

maxgekk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new b9dbf8be4685 [SPARK-51419][SQL][FOLLOWUP] Making hour function to 
accept any precision of TIME type
b9dbf8be4685 is described below

commit b9dbf8be4685eb429c46a56937ed75cb358177fe
Author: senthh <senthil.ku...@acceldata.io>
AuthorDate: Fri Apr 11 22:23:52 2025 +0200

    [SPARK-51419][SQL][FOLLOWUP] Making hour function to accept any precision 
of TIME type
    
    ### What changes were proposed in this pull request?
    This is followup PR of [SPARK-51419 
](https://github.com/apache/spark/pull/50355)
    
    ### Why are the changes needed?
    This Followup PR allows any precision in the range of [0,6] for the hour 
function
    
    ### Does this PR introduce _any_ user-facing change?
    Yes. This changes allows User to execute below query
    
    ```
    spark.sql("select hour(cast('12:00:01.123' as time(3)))").show(false)
    ```
    
    ### How was this patch tested?
    We tested by running sample query as below
    
    ```
    spark.sql("select hour(cast('12:00:01.123' as time(3)))").show(false)
    ```
    
    Output:
    
    ```
    +-----------------------------------+
    |hour(CAST(12:00:01.123 AS TIME(3)))|
    +-----------------------------------+
    |12                                                        |
    +-----------------------------------+
    
    ```
    
    ### Was this patch authored or co-authored using generative AI tooling?
    No
    
    Closes #50554 from senthh/SPARK-51419_followup.
    
    Authored-by: senthh <senthil.ku...@acceldata.io>
    Signed-off-by: Max Gekk <max.g...@gmail.com>
---
 .../spark/sql/catalyst/expressions/timeExpressions.scala     |  3 ++-
 .../sql/catalyst/expressions/TimeExpressionsSuite.scala      | 12 ++++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala
 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala
index 01d05ec5abbf..f13c4bbcb617 100644
--- 
a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala
+++ 
b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala
@@ -251,7 +251,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)
 
diff --git 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeExpressionsSuite.scala
 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeExpressionsSuite.scala
index 2abbeebfb005..72c11f2d115a 100644
--- 
a/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeExpressionsSuite.scala
+++ 
b/sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/TimeExpressionsSuite.scala
@@ -75,6 +75,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))


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to