Skip to content

Commit b9fba66

Browse files
authored
to_unixtime does not support timestamps with a timezone (#14490)
1 parent 7fd04a3 commit b9fba66

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

datafusion/functions/src/datetime/to_unixtime.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,12 @@ impl ScalarUDFImpl for ToUnixtimeFunc {
108108
DataType::Int32 | DataType::Int64 | DataType::Null | DataType::Float64 => {
109109
args[0].cast_to(&DataType::Int64, None)
110110
}
111-
DataType::Date64 | DataType::Date32 | DataType::Timestamp(_, None) => args[0]
111+
DataType::Date64 | DataType::Date32 => args[0]
112112
.cast_to(&DataType::Timestamp(TimeUnit::Second, None), None)?
113113
.cast_to(&DataType::Int64, None),
114+
DataType::Timestamp(_, tz) => args[0]
115+
.cast_to(&DataType::Timestamp(TimeUnit::Second, tz), None)?
116+
.cast_to(&DataType::Int64, None),
114117
#[allow(deprecated)] // TODO: migrate to invoke_with_args
115118
DataType::Utf8 => ToTimestampSecondsFunc::new()
116119
.invoke_batch(args, batch_size)?
@@ -120,6 +123,7 @@ impl ScalarUDFImpl for ToUnixtimeFunc {
120123
}
121124
}
122125
}
126+
123127
fn documentation(&self) -> Option<&Documentation> {
124128
self.doc()
125129
}

datafusion/sqllogictest/test_files/timestamps.slt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,16 @@ select to_unixtime('2020-09-08T12:00:00+00:00');
28722872
----
28732873
1599566400
28742874

2875+
query I
2876+
select to_unixtime(arrow_cast(to_timestamp('2023-01-14T01:01:30'), 'Timestamp(Second, Some("+05:30"))'));
2877+
----
2878+
1673638290
2879+
2880+
query I
2881+
select to_unixtime(arrow_cast(to_timestamp('2023-01-14T01:01:30'), 'Timestamp(Millisecond, None)'));
2882+
----
2883+
1673658090
2884+
28752885
query I
28762886
select to_unixtime('01-14-2023 01:01:30+05:30', '%q', '%d-%m-%Y %H/%M/%S', '%+', '%m-%d-%Y %H:%M:%S%#z');
28772887
----

0 commit comments

Comments
 (0)