Skip to content

Commit bfc5067

Browse files
petern48findepi
andauthored
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.findeisen@gmail.com>
1 parent 351675d commit bfc5067

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

datafusion/functions/src/datetime/to_local_time.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,7 @@ impl ScalarUDFImpl for ToLocalTimeFunc {
385385

386386
let first_arg = arg_types[0].clone();
387387
match &first_arg {
388+
DataType::Null => Ok(vec![Timestamp(Nanosecond, None)]),
388389
Timestamp(Nanosecond, timezone) => {
389390
Ok(vec![Timestamp(Nanosecond, timezone.clone())])
390391
}

datafusion/sqllogictest/test_files/timestamps.slt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,6 +3236,11 @@ select to_local_time('2024-04-01T00:00:20Z'::timestamp AT TIME ZONE 'Europe/Brus
32363236
----
32373237
2024-04-01T00:00:20
32383238

3239+
query P
3240+
select to_local_time(NULL);
3241+
----
3242+
NULL
3243+
32393244
query PTPT
32403245
select
32413246
time,
@@ -3263,6 +3268,7 @@ select date_bin(interval '1 day', to_local_time('2024-04-01T00:00:20Z'::timestam
32633268
statement ok
32643269
create table t AS
32653270
VALUES
3271+
(NULL),
32663272
('2024-01-01T00:00:01Z'),
32673273
('2024-02-01T00:00:01Z'),
32683274
('2024-03-01T00:00:01Z'),
@@ -3290,6 +3296,7 @@ from t;
32903296
query PPT
32913297
select column1, to_local_time(column1::timestamp), arrow_typeof(to_local_time(column1::timestamp)) from t_utc;
32923298
----
3299+
NULL NULL Timestamp(Nanosecond, None)
32933300
2024-01-01T00:00:01Z 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
32943301
2024-02-01T00:00:01Z 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
32953302
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
33063313
query PPT
33073314
select column1, to_local_time(column1), arrow_typeof(to_local_time(column1)) from t_utc;
33083315
----
3316+
NULL NULL Timestamp(Nanosecond, None)
33093317
2024-01-01T00:00:01Z 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
33103318
2024-02-01T00:00:01Z 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
33113319
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
33223330
query PPT
33233331
select column1, to_local_time(column1), arrow_typeof(to_local_time(column1)) from t_timezone;
33243332
----
3333+
NULL NULL Timestamp(Nanosecond, None)
33253334
2024-01-01T00:00:01+01:00 2024-01-01T00:00:01 Timestamp(Nanosecond, None)
33263335
2024-02-01T00:00:01+01:00 2024-02-01T00:00:01 Timestamp(Nanosecond, None)
33273336
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
33393348
query P
33403349
select date_bin(interval '1 day', to_local_time(column1)) AT TIME ZONE 'Europe/Brussels' as date_bin from t_utc;
33413350
----
3351+
NULL
33423352
2024-01-01T00:00:00+01:00
33433353
2024-02-01T00:00:00+01:00
33443354
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
33553365
query P
33563366
select date_bin(interval '1 day', to_local_time(column1)) AT TIME ZONE 'Europe/Brussels' as date_bin from t_timezone;
33573367
----
3368+
NULL
33583369
2024-01-01T00:00:00+01:00
33593370
2024-02-01T00:00:00+01:00
33603371
2024-03-01T00:00:00+01:00

0 commit comments

Comments
 (0)