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 Jun 6, 2024
1 parent a028ee6 commit d642b49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion 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 @@ -109,7 +110,14 @@ pub mod expr_fn {
),(
now,
"returns the current timestamp in nanoseconds, using the same value for all instances of now() in same statement",
),(
),
// TODO chunchun: add more doc examples
(
to_local_time,
"converts a timestamp with a timezone to a local time, returns a timestamp without timezone",
args,
),
(
to_unixtime,
"converts a string and optional formats to a Unixtime",
args,
Expand Down Expand Up @@ -278,6 +286,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 d642b49

Please sign in to comment.