Skip to content

to_unixtime does not support timestamps with a timezone #14490

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading