Skip to content

Commit

Permalink
chore: wire up the to_local_time as a UDF func
Browse files Browse the repository at this point in the history
  • Loading branch information
appletreeisyellow committed May 28, 2024
1 parent 323b77e commit cb0e2c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions datafusion/functions/src/datetime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ make_udf_function!(
make_udf_function!(now::NowFunc, NOW, now);
make_udf_function!(to_char::ToCharFunc, TO_CHAR, to_char);
make_udf_function!(to_date::ToDateFunc, TO_DATE, to_date);
make_udf_function!(to_local_time::ToLocalTimeFunc, TO_LOCAL_TIME, to_local_time);
make_udf_function!(to_unixtime::ToUnixtimeFunc, TO_UNIXTIME, to_unixtime);
make_udf_function!(to_timestamp::ToTimestampFunc, TO_TIMESTAMP, to_timestamp);
make_udf_function!(
Expand Down Expand Up @@ -249,6 +250,12 @@ pub mod expr_fn {
super::to_date().call(args)
}

// TODO chunchun: add more doc examples
#[doc = "remove the timezone from a timestamp"]
pub fn to_local_time(args: Vec<Expr>) -> Expr {
super::to_local_time().call(args)
}

#[doc = "converts a string and optional formats to a Unixtime"]
pub fn to_unixtime(args: Vec<Expr>) -> Expr {
super::to_unixtime().call(args)
Expand Down Expand Up @@ -293,6 +300,7 @@ pub fn functions() -> Vec<Arc<ScalarUDF>> {
now(),
to_char(),
to_date(),
to_local_time(),
to_unixtime(),
to_timestamp(),
to_timestamp_seconds(),
Expand Down
3 changes: 2 additions & 1 deletion datafusion/functions/src/datetime/to_local_time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl ScalarUDFImpl for ToLocalTimeFunc {
Timestamp(Millisecond, _) => Ok(Timestamp(Millisecond, None)),
Timestamp(Second, _) => Ok(Timestamp(Second, None)),
_ => exec_err!(
"The date_bin function can only accept timestamp as the second arg."
"The to_local_time function can only accept timestamp as the second arg."
),
}
}
Expand All @@ -140,6 +140,7 @@ impl ScalarUDFImpl for ToLocalTimeFunc {
);
}

// TODO chunchun: support more input data types
self.to_local_time(args)
}
}
Expand Down

0 comments on commit cb0e2c4

Please sign in to comment.