the-sakthi opened a new pull request, #50336:
URL: https://github.com/apache/spark/pull/50336

   ### What changes were proposed in this pull request?
   This PR adds support for a new function current_time() which returns the 
current time at the start of query evaluation.
   
   ```bash
   scala> spark.sql("SELECT current_time(0);").show()
   +--------------+
   |current_time()|
   +--------------+
   |      04:48:47|
   +--------------+
   
   
   scala> spark.sql("SELECT current_time();").show()
   +---------------+
   | current_time()|
   +---------------+
   |04:48:51.609168|
   +---------------+
   
   
   scala> spark.sql("SELECT current_time(3);").show()
   +--------------+
   |current_time()|
   +--------------+
   |  04:48:54.846|
   +--------------+
   
   
   scala> spark.sql("SELECT current_time(6);").show()
   +---------------+
   | current_time()|
   +---------------+
   |04:48:59.222348|
   +---------------+
   
   scala> spark.sql("SELECT current_time(7);").show()
   org.apache.spark.sql.catalyst.ExtendedAnalysisException: 
[DATATYPE_MISMATCH.TYPE_CHECK_FAILURE_WITH_HINT] Cannot resolve 
"current_time()" due to data type mismatch: Invalid precision 7. Must be 
between 0 and 6.. SQLSTATE: 42K09; line 1 pos 7;
   'Project [unresolvedalias(current_time(7))]
   +- OneRowRelation
   
     at 
org.apache.spark.sql.catalyst.analysis.package$AnalysisErrorAt.failAnalysis(package.scala:52)
     ...
   ```
   
   ### Why are the changes needed?
   Adds a built-in current_time([n]) function returning just the time portion 
(in a TIME(n) type). This aligns Spark with other SQL systems offering a native 
time function, improves convenience for time-only queries, and complements 
existing functions like current_date and current_timestamp.
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, adds a new function. Users can now get the current time using this 
function.
   
   ### How was this patch tested?
   Manual testing.
   
   
   ### Pending
   - Support for current_time [i.e. without any braces]
   - Implementation of codegen (currently extending CodegenFallback)
   - Addition of UTs.
   - Use inbuilt functions for `computeMicrosAtPrecision`
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No
   


-- 
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

Reply via email to