use std::sync::Arc;
use datafusion_expr::ScalarUDF;
mod common;
mod current_date;
mod current_time;
mod date_bin;
mod date_part;
mod date_trunc;
mod from_unixtime;
mod make_date;
mod now;
mod to_char;
mod to_date;
mod to_timestamp;
mod to_unixtime;
make_udf_function!(current_date::CurrentDateFunc, CURRENT_DATE, current_date);
make_udf_function!(current_time::CurrentTimeFunc, CURRENT_TIME, current_time);
make_udf_function!(date_bin::DateBinFunc, DATE_BIN, date_bin);
make_udf_function!(date_part::DatePartFunc, DATE_PART, date_part);
make_udf_function!(date_trunc::DateTruncFunc, DATE_TRUNC, date_trunc);
make_udf_function!(make_date::MakeDateFunc, MAKE_DATE, make_date);
make_udf_function!(
from_unixtime::FromUnixtimeFunc,
FROM_UNIXTIME,
from_unixtime
);
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_unixtime::ToUnixtimeFunc, TO_UNIXTIME, to_unixtime);
make_udf_function!(to_timestamp::ToTimestampFunc, TO_TIMESTAMP, to_timestamp);
make_udf_function!(
to_timestamp::ToTimestampSecondsFunc,
TO_TIMESTAMP_SECONDS,
to_timestamp_seconds
);
make_udf_function!(
to_timestamp::ToTimestampMillisFunc,
TO_TIMESTAMP_MILLIS,
to_timestamp_millis
);
make_udf_function!(
to_timestamp::ToTimestampMicrosFunc,
TO_TIMESTAMP_MICROS,
to_timestamp_micros
);
make_udf_function!(
to_timestamp::ToTimestampNanosFunc,
TO_TIMESTAMP_NANOS,
to_timestamp_nanos
);
pub mod expr_fn {
use datafusion_expr::Expr;
#[doc = "returns current UTC date as a Date32 value"]
pub fn current_date() -> Expr {
super::current_date().call(vec![])
}
#[doc = "returns current UTC time as a Time64 value"]
pub fn current_time() -> Expr {
super::current_time().call(vec![])
}
#[doc = "coerces an arbitrary timestamp to the start of the nearest specified interval"]
pub fn date_bin(stride: Expr, source: Expr, origin: Expr) -> Expr {
super::date_bin().call(vec![stride, source, origin])
}
#[doc = "extracts a subfield from the date"]
pub fn date_part(part: Expr, date: Expr) -> Expr {
super::date_part().call(vec![part, date])
}
#[doc = "truncates the date to a specified level of precision"]
pub fn date_trunc(part: Expr, date: Expr) -> Expr {
super::date_trunc().call(vec![part, date])
}
#[doc = "converts an integer to RFC3339 timestamp format string"]
pub fn from_unixtime(unixtime: Expr) -> Expr {
super::from_unixtime().call(vec![unixtime])
}
#[doc = "make a date from year, month and day component parts"]
pub fn make_date(year: Expr, month: Expr, day: Expr) -> Expr {
super::make_date().call(vec![year, month, day])
}
#[doc = "returns the current timestamp in nanoseconds, using the same value for all instances of now() in same statement"]
pub fn now() -> Expr {
super::now().call(vec![])
}
pub fn to_char(datetime: Expr, format: Expr) -> Expr {
super::to_char().call(vec![datetime, format])
}
pub fn to_date(args: Vec<Expr>) -> Expr {
super::to_date().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)
}
#[doc = "converts a string and optional formats to a `Timestamp(Nanoseconds, None)`"]
pub fn to_timestamp(args: Vec<Expr>) -> Expr {
super::to_timestamp().call(args)
}
#[doc = "converts a string and optional formats to a `Timestamp(Seconds, None)`"]
pub fn to_timestamp_seconds(args: Vec<Expr>) -> Expr {
super::to_timestamp_seconds().call(args)
}
#[doc = "converts a string and optional formats to a `Timestamp(Milliseconds, None)`"]
pub fn to_timestamp_millis(args: Vec<Expr>) -> Expr {
super::to_timestamp_millis().call(args)
}
#[doc = "converts a string and optional formats to a `Timestamp(Microseconds, None)`"]
pub fn to_timestamp_micros(args: Vec<Expr>) -> Expr {
super::to_timestamp_micros().call(args)
}
#[doc = "converts a string and optional formats to a `Timestamp(Nanoseconds, None)`"]
pub fn to_timestamp_nanos(args: Vec<Expr>) -> Expr {
super::to_timestamp_nanos().call(args)
}
}
pub fn functions() -> Vec<Arc<ScalarUDF>> {
vec![
current_date(),
current_time(),
date_bin(),
date_part(),
date_trunc(),
from_unixtime(),
make_date(),
now(),
to_char(),
to_date(),
to_unixtime(),
to_timestamp(),
to_timestamp_seconds(),
to_timestamp_millis(),
to_timestamp_micros(),
to_timestamp_nanos(),
]
}