Skip to content

Commit c67d89d

Browse files
committed
[task #9511] move date_part, date_trunc, date_bin functions to datafusion-functions
Signed-off-by: tangruilin <[email protected]>
1 parent b1d8082 commit c67d89d

File tree

15 files changed

+1146
-971
lines changed

15 files changed

+1146
-971
lines changed

datafusion-cli/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/expr/src/built_in_function.rs

+2-66
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,6 @@ pub enum BuiltinScalarFunction {
182182
Concat,
183183
/// concat_ws
184184
ConcatWithSeparator,
185-
/// date_part
186-
DatePart,
187-
/// date_trunc
188-
DateTrunc,
189185
/// date_bin
190186
DateBin,
191187
/// ends_with
@@ -385,8 +381,6 @@ impl BuiltinScalarFunction {
385381
BuiltinScalarFunction::Chr => Volatility::Immutable,
386382
BuiltinScalarFunction::Concat => Volatility::Immutable,
387383
BuiltinScalarFunction::ConcatWithSeparator => Volatility::Immutable,
388-
BuiltinScalarFunction::DatePart => Volatility::Immutable,
389-
BuiltinScalarFunction::DateTrunc => Volatility::Immutable,
390384
BuiltinScalarFunction::DateBin => Volatility::Immutable,
391385
BuiltinScalarFunction::EndsWith => Volatility::Immutable,
392386
BuiltinScalarFunction::InitCap => Volatility::Immutable,
@@ -609,8 +603,7 @@ impl BuiltinScalarFunction {
609603
}
610604
BuiltinScalarFunction::Concat => Ok(Utf8),
611605
BuiltinScalarFunction::ConcatWithSeparator => Ok(Utf8),
612-
BuiltinScalarFunction::DatePart => Ok(Float64),
613-
BuiltinScalarFunction::DateBin | BuiltinScalarFunction::DateTrunc => {
606+
BuiltinScalarFunction::DateBin => {
614607
match &input_expr_types[1] {
615608
Timestamp(Nanosecond, None) | Utf8 | Null => {
616609
Ok(Timestamp(Nanosecond, None))
@@ -965,31 +958,6 @@ impl BuiltinScalarFunction {
965958
],
966959
self.volatility(),
967960
),
968-
BuiltinScalarFunction::DateTrunc => Signature::one_of(
969-
vec![
970-
Exact(vec![Utf8, Timestamp(Nanosecond, None)]),
971-
Exact(vec![
972-
Utf8,
973-
Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),
974-
]),
975-
Exact(vec![Utf8, Timestamp(Microsecond, None)]),
976-
Exact(vec![
977-
Utf8,
978-
Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),
979-
]),
980-
Exact(vec![Utf8, Timestamp(Millisecond, None)]),
981-
Exact(vec![
982-
Utf8,
983-
Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),
984-
]),
985-
Exact(vec![Utf8, Timestamp(Second, None)]),
986-
Exact(vec![
987-
Utf8,
988-
Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),
989-
]),
990-
],
991-
self.volatility(),
992-
),
993961
BuiltinScalarFunction::DateBin => {
994962
let base_sig = |array_type: TimeUnit| {
995963
vec![
@@ -1040,33 +1008,6 @@ impl BuiltinScalarFunction {
10401008

10411009
Signature::one_of(full_sig, self.volatility())
10421010
}
1043-
BuiltinScalarFunction::DatePart => Signature::one_of(
1044-
vec![
1045-
Exact(vec![Utf8, Timestamp(Nanosecond, None)]),
1046-
Exact(vec![
1047-
Utf8,
1048-
Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),
1049-
]),
1050-
Exact(vec![Utf8, Timestamp(Millisecond, None)]),
1051-
Exact(vec![
1052-
Utf8,
1053-
Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),
1054-
]),
1055-
Exact(vec![Utf8, Timestamp(Microsecond, None)]),
1056-
Exact(vec![
1057-
Utf8,
1058-
Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),
1059-
]),
1060-
Exact(vec![Utf8, Timestamp(Second, None)]),
1061-
Exact(vec![
1062-
Utf8,
1063-
Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),
1064-
]),
1065-
Exact(vec![Utf8, Date64]),
1066-
Exact(vec![Utf8, Date32]),
1067-
],
1068-
self.volatility(),
1069-
),
10701011
BuiltinScalarFunction::SplitPart => Signature::one_of(
10711012
vec![
10721013
Exact(vec![Utf8, Utf8, Int64]),
@@ -1258,10 +1199,7 @@ impl BuiltinScalarFunction {
12581199
| BuiltinScalarFunction::Pi
12591200
) {
12601201
Some(vec![Some(true)])
1261-
} else if matches!(
1262-
&self,
1263-
BuiltinScalarFunction::DateTrunc | BuiltinScalarFunction::DateBin
1264-
) {
1202+
} else if matches!(&self, BuiltinScalarFunction::DateBin) {
12651203
Some(vec![None, Some(true)])
12661204
} else if *self == BuiltinScalarFunction::Log {
12671205
Some(vec![Some(true), Some(false)])
@@ -1356,8 +1294,6 @@ impl BuiltinScalarFunction {
13561294
BuiltinScalarFunction::CurrentTime => &["current_time"],
13571295
BuiltinScalarFunction::MakeDate => &["make_date"],
13581296
BuiltinScalarFunction::DateBin => &["date_bin"],
1359-
BuiltinScalarFunction::DateTrunc => &["date_trunc", "datetrunc"],
1360-
BuiltinScalarFunction::DatePart => &["date_part", "datepart"],
13611297
BuiltinScalarFunction::ToChar => &["to_char", "date_format"],
13621298
BuiltinScalarFunction::FromUnixtime => &["from_unixtime"],
13631299

datafusion/expr/src/expr_fn.rs

-4
Original file line numberDiff line numberDiff line change
@@ -825,8 +825,6 @@ nary_scalar_expr!(
825825
);
826826

827827
// date functions
828-
scalar_expr!(DatePart, date_part, part date, "extracts a subfield from the date");
829-
scalar_expr!(DateTrunc, date_trunc, part date, "truncates the date to a specified level of precision");
830828
scalar_expr!(DateBin, date_bin, stride source origin, "coerces an arbitrary timestamp to the start of the nearest specified interval");
831829
scalar_expr!(
832830
ToChar,
@@ -1315,8 +1313,6 @@ mod test {
13151313
test_scalar_expr!(Trim, trim, string);
13161314
test_scalar_expr!(Upper, upper, string);
13171315

1318-
test_scalar_expr!(DatePart, date_part, part, date);
1319-
test_scalar_expr!(DateTrunc, date_trunc, part, date);
13201316
test_scalar_expr!(DateBin, date_bin, stride, source, origin);
13211317
test_scalar_expr!(FromUnixtime, from_unixtime, unixtime);
13221318

0 commit comments

Comments
 (0)