Skip to content

Commit 205777b

Browse files
authored
Move make_date, to_char to datafusion-functions (#9601)
* Move make_date, to_char to datafusion-functions * Update post merge to remove datetime_expressions.rs * Fix benchmarks. * Cargo fmt.
1 parent 9d0c05b commit 205777b

18 files changed

Lines changed: 572 additions & 491 deletions

File tree

datafusion-cli/Cargo.lock

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ use std::fmt;
2222
use std::str::FromStr;
2323
use std::sync::{Arc, OnceLock};
2424

25-
use crate::signature::TIMEZONE_WILDCARD;
2625
use crate::type_coercion::functions::data_types;
2726
use crate::{FuncMonotonicity, Signature, TypeSignature, Volatility};
2827

29-
use arrow::datatypes::{DataType, Field, TimeUnit};
28+
use arrow::datatypes::{DataType, Field};
3029
use datafusion_common::{plan_err, DataFusionError, Result};
3130

3231
use strum::IntoEnumIterator;
@@ -190,8 +189,6 @@ pub enum BuiltinScalarFunction {
190189
Substr,
191190
/// to_hex
192191
ToHex,
193-
/// make_date
194-
MakeDate,
195192
/// translate
196193
Translate,
197194
/// trim
@@ -208,8 +205,6 @@ pub enum BuiltinScalarFunction {
208205
SubstrIndex,
209206
/// find_in_set
210207
FindInSet,
211-
/// to_char
212-
ToChar,
213208
}
214209

215210
/// Maps the sql function name to `BuiltinScalarFunction`
@@ -335,8 +330,6 @@ impl BuiltinScalarFunction {
335330
BuiltinScalarFunction::Strpos => Volatility::Immutable,
336331
BuiltinScalarFunction::Substr => Volatility::Immutable,
337332
BuiltinScalarFunction::ToHex => Volatility::Immutable,
338-
BuiltinScalarFunction::ToChar => Volatility::Immutable,
339-
BuiltinScalarFunction::MakeDate => Volatility::Immutable,
340333
BuiltinScalarFunction::Translate => Volatility::Immutable,
341334
BuiltinScalarFunction::Trim => Volatility::Immutable,
342335
BuiltinScalarFunction::Upper => Volatility::Immutable,
@@ -490,8 +483,6 @@ impl BuiltinScalarFunction {
490483
BuiltinScalarFunction::FindInSet => {
491484
utf8_to_int_type(&input_expr_types[0], "find_in_set")
492485
}
493-
BuiltinScalarFunction::ToChar => Ok(Utf8),
494-
BuiltinScalarFunction::MakeDate => Ok(Date32),
495486
BuiltinScalarFunction::Translate => {
496487
utf8_to_str_type(&input_expr_types[0], "translate")
497488
}
@@ -567,7 +558,6 @@ impl BuiltinScalarFunction {
567558
/// Return the argument [`Signature`] supported by this function
568559
pub fn signature(&self) -> Signature {
569560
use DataType::*;
570-
use TimeUnit::*;
571561
use TypeSignature::*;
572562
// note: the physical expression must accept the type returned by this function or the execution panics.
573563

@@ -651,41 +641,6 @@ impl BuiltinScalarFunction {
651641
vec![Exact(vec![Utf8, Int64]), Exact(vec![LargeUtf8, Int64])],
652642
self.volatility(),
653643
),
654-
BuiltinScalarFunction::ToChar => Signature::one_of(
655-
vec![
656-
Exact(vec![Date32, Utf8]),
657-
Exact(vec![Date64, Utf8]),
658-
Exact(vec![Time32(Millisecond), Utf8]),
659-
Exact(vec![Time32(Second), Utf8]),
660-
Exact(vec![Time64(Microsecond), Utf8]),
661-
Exact(vec![Time64(Nanosecond), Utf8]),
662-
Exact(vec![Timestamp(Second, None), Utf8]),
663-
Exact(vec![
664-
Timestamp(Second, Some(TIMEZONE_WILDCARD.into())),
665-
Utf8,
666-
]),
667-
Exact(vec![Timestamp(Millisecond, None), Utf8]),
668-
Exact(vec![
669-
Timestamp(Millisecond, Some(TIMEZONE_WILDCARD.into())),
670-
Utf8,
671-
]),
672-
Exact(vec![Timestamp(Microsecond, None), Utf8]),
673-
Exact(vec![
674-
Timestamp(Microsecond, Some(TIMEZONE_WILDCARD.into())),
675-
Utf8,
676-
]),
677-
Exact(vec![Timestamp(Nanosecond, None), Utf8]),
678-
Exact(vec![
679-
Timestamp(Nanosecond, Some(TIMEZONE_WILDCARD.into())),
680-
Utf8,
681-
]),
682-
Exact(vec![Duration(Second), Utf8]),
683-
Exact(vec![Duration(Millisecond), Utf8]),
684-
Exact(vec![Duration(Microsecond), Utf8]),
685-
Exact(vec![Duration(Nanosecond), Utf8]),
686-
],
687-
self.volatility(),
688-
),
689644
BuiltinScalarFunction::SplitPart => Signature::one_of(
690645
vec![
691646
Exact(vec![Utf8, Utf8, Int64]),
@@ -821,11 +776,6 @@ impl BuiltinScalarFunction {
821776
// will be as good as the number of digits in the number
822777
Signature::uniform(1, vec![Float64, Float32], self.volatility())
823778
}
824-
BuiltinScalarFunction::MakeDate => Signature::uniform(
825-
3,
826-
vec![Int32, Int64, UInt32, UInt64, Utf8],
827-
self.volatility(),
828-
),
829779
BuiltinScalarFunction::Iszero => Signature::one_of(
830780
vec![Exact(vec![Float32]), Exact(vec![Float64])],
831781
self.volatility(),
@@ -943,10 +893,6 @@ impl BuiltinScalarFunction {
943893
BuiltinScalarFunction::SubstrIndex => &["substr_index", "substring_index"],
944894
BuiltinScalarFunction::FindInSet => &["find_in_set"],
945895

946-
// time/date functions
947-
BuiltinScalarFunction::MakeDate => &["make_date"],
948-
BuiltinScalarFunction::ToChar => &["to_char", "date_format"],
949-
950896
// hashing functions
951897
BuiltinScalarFunction::ArrayElement => &[
952898
"array_element",

datafusion/expr/src/expr_fn.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,6 @@ nary_scalar_expr!(
768768
"replace the substring of string that starts at the start'th character and extends for count characters with new substring"
769769
);
770770

771-
// date functions
772-
scalar_expr!(
773-
ToChar,
774-
to_char,
775-
datetime format,
776-
"converts a date, time, timestamp or duration to a string based on the provided format"
777-
);
778-
scalar_expr!(MakeDate, make_date, year month day, "make a date from year, month and day component parts");
779771
scalar_expr!(Nanvl, nanvl, x y, "returns x if x is not NaN otherwise returns y");
780772
scalar_expr!(
781773
Iszero,

datafusion/functions/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ path = "src/lib.rs"
5858
[dependencies]
5959
arrow = { workspace = true }
6060
arrow-array = { workspace = true }
61+
arrow-schema = { workspace = true }
6162
base64 = { version = "0.22", optional = true }
6263
blake2 = { version = "^0.10.2", optional = true }
6364
blake3 = { version = "1.0", optional = true }
@@ -85,3 +86,11 @@ name = "to_timestamp"
8586
[[bench]]
8687
harness = false
8788
name = "regx"
89+
90+
[[bench]]
91+
harness = false
92+
name = "make_date"
93+
94+
[[bench]]
95+
harness = false
96+
name = "to_char"

datafusion/physical-expr/benches/make_date.rs renamed to datafusion/functions/benches/make_date.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rand::Rng;
2626

2727
use datafusion_common::ScalarValue;
2828
use datafusion_expr::ColumnarValue;
29-
use datafusion_physical_expr::datetime_expressions::make_date;
29+
use datafusion_functions::datetime::make_date;
3030

3131
fn years(rng: &mut ThreadRng) -> Int32Array {
3232
let mut years = vec![];
@@ -63,7 +63,8 @@ fn criterion_benchmark(c: &mut Criterion) {
6363

6464
b.iter(|| {
6565
black_box(
66-
make_date(&[years.clone(), months.clone(), days.clone()])
66+
make_date()
67+
.invoke(&[years.clone(), months.clone(), days.clone()])
6768
.expect("make_date should work on valid values"),
6869
)
6970
})
@@ -77,7 +78,8 @@ fn criterion_benchmark(c: &mut Criterion) {
7778

7879
b.iter(|| {
7980
black_box(
80-
make_date(&[year.clone(), months.clone(), days.clone()])
81+
make_date()
82+
.invoke(&[year.clone(), months.clone(), days.clone()])
8183
.expect("make_date should work on valid values"),
8284
)
8385
})
@@ -91,7 +93,8 @@ fn criterion_benchmark(c: &mut Criterion) {
9193

9294
b.iter(|| {
9395
black_box(
94-
make_date(&[year.clone(), month.clone(), days.clone()])
96+
make_date()
97+
.invoke(&[year.clone(), month.clone(), days.clone()])
9598
.expect("make_date should work on valid values"),
9699
)
97100
})
@@ -104,7 +107,8 @@ fn criterion_benchmark(c: &mut Criterion) {
104107

105108
b.iter(|| {
106109
black_box(
107-
make_date(&[year.clone(), month.clone(), day.clone()])
110+
make_date()
111+
.invoke(&[year.clone(), month.clone(), day.clone()])
108112
.expect("make_date should work on valid values"),
109113
)
110114
})

datafusion/physical-expr/benches/to_char.rs renamed to datafusion/functions/benches/to_char.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rand::Rng;
3030
use datafusion_common::ScalarValue;
3131
use datafusion_common::ScalarValue::TimestampNanosecond;
3232
use datafusion_expr::ColumnarValue;
33-
use datafusion_physical_expr::datetime_expressions::to_char;
33+
use datafusion_functions::datetime::to_char;
3434

3535
fn random_date_in_range(
3636
rng: &mut ThreadRng,
@@ -87,7 +87,8 @@ fn criterion_benchmark(c: &mut Criterion) {
8787

8888
b.iter(|| {
8989
black_box(
90-
to_char(&[data.clone(), patterns.clone()])
90+
to_char()
91+
.invoke(&[data.clone(), patterns.clone()])
9192
.expect("to_char should work on valid values"),
9293
)
9394
})
@@ -101,7 +102,8 @@ fn criterion_benchmark(c: &mut Criterion) {
101102

102103
b.iter(|| {
103104
black_box(
104-
to_char(&[data.clone(), patterns.clone()])
105+
to_char()
106+
.invoke(&[data.clone(), patterns.clone()])
105107
.expect("to_char should work on valid values"),
106108
)
107109
})
@@ -123,7 +125,8 @@ fn criterion_benchmark(c: &mut Criterion) {
123125

124126
b.iter(|| {
125127
black_box(
126-
to_char(&[data.clone(), pattern.clone()])
128+
to_char()
129+
.invoke(&[data.clone(), pattern.clone()])
127130
.expect("to_char should work on valid values"),
128131
)
129132
})

0 commit comments

Comments
 (0)