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

findepi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new bfc5067718 bug: Support null as argument to to_local_time (#17491)
bfc5067718 is described below

commit bfc5067718a3ddcb87531b5a9633605792078546
Author: Peter Nguyen <petern0...@gmail.com>
AuthorDate: Thu Sep 11 22:57:31 2025 -0700

    bug: Support null as argument to to_local_time (#17491)
    
    * Support null argument for to_local_time
    
    * Add scalar null test
    
    * Add array null tests
    
    * remove unreachable lines
    
    because to_local_time impls coerce_types, the Null argument gets coerced
    
    ---------
    
    Co-authored-by: Piotr Findeisen <piotr.findei...@gmail.com>
---
 datafusion/functions/src/datetime/to_local_time.rs |  1 +
 datafusion/sqllogictest/test_files/timestamps.slt  | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/datafusion/functions/src/datetime/to_local_time.rs 
b/datafusion/functions/src/datetime/to_local_time.rs
index d0a457ba8f..a8c413dd0e 100644
--- a/datafusion/functions/src/datetime/to_local_time.rs
+++ b/datafusion/functions/src/datetime/to_local_time.rs
@@ -385,6 +385,7 @@ impl ScalarUDFImpl for ToLocalTimeFunc {
 
         let first_arg = arg_types[0].clone();
         match &first_arg {
+            DataType::Null => Ok(vec![Timestamp(Nanosecond, None)]),
             Timestamp(Nanosecond, timezone) => {
                 Ok(vec![Timestamp(Nanosecond, timezone.clone())])
             }
diff --git a/datafusion/sqllogictest/test_files/timestamps.slt 
b/datafusion/sqllogictest/test_files/timestamps.slt
index f48994431d..f8b7ccc6ae 100644
--- a/datafusion/sqllogictest/test_files/timestamps.slt
+++ b/datafusion/sqllogictest/test_files/timestamps.slt
@@ -3236,6 +3236,11 @@ select to_local_time('2024-04-01T00:00:20Z'::timestamp 
AT TIME ZONE 'Europe/Brus
 ----
 2024-04-01T00:00:20
 
+query P
+select to_local_time(NULL);
+----
+NULL
+
 query PTPT
 select
   time,
@@ -3263,6 +3268,7 @@ select date_bin(interval '1 day', 
to_local_time('2024-04-01T00:00:20Z'::timestam
 statement ok
 create table t AS
 VALUES
+  (NULL),
   ('2024-01-01T00:00:01Z'),
   ('2024-02-01T00:00:01Z'),
   ('2024-03-01T00:00:01Z'),
@@ -3290,6 +3296,7 @@ from t;
 query PPT
 select column1, to_local_time(column1::timestamp), 
arrow_typeof(to_local_time(column1::timestamp)) from t_utc;
 ----
+NULL NULL Timestamp(Nanosecond, None)
 2024-01-01T00:00:01Z 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
 2024-02-01T00:00:01Z 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
 2024-03-01T00:00:01Z 2024-03-01T00:00:01 Timestamp(Nanosecond, None)
@@ -3306,6 +3313,7 @@ select column1, to_local_time(column1::timestamp), 
arrow_typeof(to_local_time(co
 query PPT
 select column1, to_local_time(column1), arrow_typeof(to_local_time(column1)) 
from t_utc;
 ----
+NULL NULL Timestamp(Nanosecond, None)
 2024-01-01T00:00:01Z 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
 2024-02-01T00:00:01Z 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
 2024-03-01T00:00:01Z 2024-03-01T00:00:01 Timestamp(Nanosecond, None)
@@ -3322,6 +3330,7 @@ select column1, to_local_time(column1), 
arrow_typeof(to_local_time(column1)) fro
 query PPT
 select column1, to_local_time(column1), arrow_typeof(to_local_time(column1)) 
from t_timezone;
 ----
+NULL NULL Timestamp(Nanosecond, None)
 2024-01-01T00:00:01+01:00 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
 2024-02-01T00:00:01+01:00 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
 2024-03-01T00:00:01+01:00 2024-03-01T00:00:01 Timestamp(Nanosecond, None)
@@ -3339,6 +3348,7 @@ select column1, to_local_time(column1), 
arrow_typeof(to_local_time(column1)) fro
 query P
 select date_bin(interval '1 day', to_local_time(column1)) AT TIME ZONE 
'Europe/Brussels' as date_bin from t_utc;
 ----
+NULL
 2024-01-01T00:00:00+01:00
 2024-02-01T00:00:00+01:00
 2024-03-01T00:00:00+01:00
@@ -3355,6 +3365,7 @@ select date_bin(interval '1 day', to_local_time(column1)) 
AT TIME ZONE 'Europe/B
 query P
 select date_bin(interval '1 day', to_local_time(column1)) AT TIME ZONE 
'Europe/Brussels' as date_bin from t_timezone;
 ----
+NULL
 2024-01-01T00:00:00+01:00
 2024-02-01T00:00:00+01:00
 2024-03-01T00:00:00+01:00


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

Reply via email to