Skip to content

Commit

Permalink
to_unixtime does not support timestamps with a timezone (#14490)
Browse files Browse the repository at this point in the history
  • Loading branch information
Omega359 authored Feb 6, 2025
1 parent 7fd04a3 commit b9fba66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion datafusion/functions/src/datetime/to_unixtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,12 @@ impl ScalarUDFImpl for ToUnixtimeFunc {
DataType::Int32 | DataType::Int64 | DataType::Null | DataType::Float64 => {
args[0].cast_to(&DataType::Int64, None)
}
DataType::Date64 | DataType::Date32 | DataType::Timestamp(_, None) => args[0]
DataType::Date64 | DataType::Date32 => args[0]
.cast_to(&DataType::Timestamp(TimeUnit::Second, None), None)?
.cast_to(&DataType::Int64, None),
DataType::Timestamp(_, tz) => args[0]
.cast_to(&DataType::Timestamp(TimeUnit::Second, tz), None)?
.cast_to(&DataType::Int64, None),
#[allow(deprecated)] // TODO: migrate to invoke_with_args
DataType::Utf8 => ToTimestampSecondsFunc::new()
.invoke_batch(args, batch_size)?
Expand All @@ -120,6 +123,7 @@ impl ScalarUDFImpl for ToUnixtimeFunc {
}
}
}

fn documentation(&self) -> Option<&Documentation> {
self.doc()
}
Expand Down
10 changes: 10 additions & 0 deletions datafusion/sqllogictest/test_files/timestamps.slt
Original file line number Diff line number Diff line change
Expand Up @@ -2872,6 +2872,16 @@ select to_unixtime('2020-09-08T12:00:00+00:00');
----
1599566400

query I
select to_unixtime(arrow_cast(to_timestamp('2023-01-14T01:01:30'), 'Timestamp(Second, Some("+05:30"))'));
----
1673638290

query I
select to_unixtime(arrow_cast(to_timestamp('2023-01-14T01:01:30'), 'Timestamp(Millisecond, None)'));
----
1673658090

query I
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');
----
Expand Down

0 comments on commit b9fba66

Please sign in to comment.