Skip to content

Commit 98cd19e

Browse files
goldmedalalamb
andauthored
Remove duplicate function name in its aliases list (#10661)
* remove duplicate name in function name aliases for array-function * add test for registering default functions * rename test case * add tests for agg and core function and refactor the test * remove unused mut * add comments for public function * cargo fmt * fix clippy * fix missing list_element * fix clippy * remove duplicate aliase name for median * add test for function list and remove the test for SessionState * remove the debug message * revert the change for medain and remove case insensitive test --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 3dc1773 commit 98cd19e

File tree

24 files changed

+143
-80
lines changed

24 files changed

+143
-80
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl Default for FirstValue {
7272
impl FirstValue {
7373
pub fn new() -> Self {
7474
Self {
75-
aliases: vec![String::from("FIRST_VALUE"), String::from("first_value")],
75+
aliases: vec![String::from("first_value")],
7676
signature: Signature::one_of(
7777
vec![
7878
// TODO: we can introduce more strict signature that only numeric of array types are allowed
@@ -372,7 +372,7 @@ impl Default for LastValue {
372372
impl LastValue {
373373
pub fn new() -> Self {
374374
Self {
375-
aliases: vec![String::from("LAST_VALUE"), String::from("last_value")],
375+
aliases: vec![String::from("last_value")],
376376
signature: Signature::one_of(
377377
vec![
378378
// TODO: we can introduce more strict signature that only numeric of array types are allowed

datafusion/functions-aggregate/src/lib.rs

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,20 @@ pub mod expr_fn {
7272
pub use super::median::median;
7373
}
7474

75-
/// Registers all enabled packages with a [`FunctionRegistry`]
76-
pub fn register_all(registry: &mut dyn FunctionRegistry) -> Result<()> {
77-
let functions: Vec<Arc<AggregateUDF>> = vec![
75+
/// Returns all default aggregate functions
76+
pub fn all_default_aggregate_functions() -> Vec<Arc<AggregateUDF>> {
77+
vec![
7878
first_last::first_value_udaf(),
7979
first_last::last_value_udaf(),
8080
covariance::covar_samp_udaf(),
8181
covariance::covar_pop_udaf(),
8282
median::median_udaf(),
83-
];
83+
]
84+
}
85+
86+
/// Registers all enabled packages with a [`FunctionRegistry`]
87+
pub fn register_all(registry: &mut dyn FunctionRegistry) -> Result<()> {
88+
let functions: Vec<Arc<AggregateUDF>> = all_default_aggregate_functions();
8489

8590
functions.into_iter().try_for_each(|udf| {
8691
let existing_udaf = registry.register_udaf(udf)?;
@@ -92,3 +97,30 @@ pub fn register_all(registry: &mut dyn FunctionRegistry) -> Result<()> {
9297

9398
Ok(())
9499
}
100+
101+
#[cfg(test)]
102+
mod tests {
103+
use crate::all_default_aggregate_functions;
104+
use datafusion_common::Result;
105+
use std::collections::HashSet;
106+
107+
#[test]
108+
fn test_no_duplicate_name() -> Result<()> {
109+
let mut names = HashSet::new();
110+
for func in all_default_aggregate_functions() {
111+
assert!(
112+
names.insert(func.name().to_string()),
113+
"duplicate function name: {}",
114+
func.name()
115+
);
116+
for alias in func.aliases() {
117+
assert!(
118+
names.insert(alias.to_string()),
119+
"duplicate function name: {}",
120+
alias
121+
);
122+
}
123+
}
124+
Ok(())
125+
}
126+
}

datafusion/functions-array/src/array_has.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ impl ArrayHas {
6868
Self {
6969
signature: Signature::array_and_element(Volatility::Immutable),
7070
aliases: vec![
71-
String::from("array_has"),
7271
String::from("list_has"),
7372
String::from("array_contains"),
7473
String::from("list_contains"),
@@ -140,7 +139,7 @@ impl ArrayHasAll {
140139
pub fn new() -> Self {
141140
Self {
142141
signature: Signature::any(2, Volatility::Immutable),
143-
aliases: vec![String::from("array_has_all"), String::from("list_has_all")],
142+
aliases: vec![String::from("list_has_all")],
144143
}
145144
}
146145
}
@@ -203,7 +202,7 @@ impl ArrayHasAny {
203202
pub fn new() -> Self {
204203
Self {
205204
signature: Signature::any(2, Volatility::Immutable),
206-
aliases: vec![String::from("array_has_any"), String::from("list_has_any")],
205+
aliases: vec![String::from("list_has_any")],
207206
}
208207
}
209208
}

datafusion/functions-array/src/cardinality.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Cardinality {
4040
pub fn new() -> Self {
4141
Self {
4242
signature: Signature::array(Volatility::Immutable),
43-
aliases: vec![String::from("cardinality")],
43+
aliases: vec![],
4444
}
4545
}
4646
}

datafusion/functions-array/src/concat.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ impl ArrayAppend {
5959
Self {
6060
signature: Signature::array_and_element(Volatility::Immutable),
6161
aliases: vec![
62-
String::from("array_append"),
6362
String::from("list_append"),
6463
String::from("array_push_back"),
6564
String::from("list_push_back"),
@@ -119,7 +118,6 @@ impl ArrayPrepend {
119118
Self {
120119
signature: Signature::element_and_array(Volatility::Immutable),
121120
aliases: vec![
122-
String::from("array_prepend"),
123121
String::from("list_prepend"),
124122
String::from("array_push_front"),
125123
String::from("list_push_front"),
@@ -178,7 +176,6 @@ impl ArrayConcat {
178176
Self {
179177
signature: Signature::variadic_any(Volatility::Immutable),
180178
aliases: vec![
181-
String::from("array_concat"),
182179
String::from("array_cat"),
183180
String::from("list_concat"),
184181
String::from("list_cat"),

datafusion/functions-array/src/dimension.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl ArrayDims {
5050
pub fn new() -> Self {
5151
Self {
5252
signature: Signature::array(Volatility::Immutable),
53-
aliases: vec!["array_dims".to_string(), "list_dims".to_string()],
53+
aliases: vec!["list_dims".to_string()],
5454
}
5555
}
5656
}
@@ -104,7 +104,7 @@ impl ArrayNdims {
104104
pub fn new() -> Self {
105105
Self {
106106
signature: Signature::array(Volatility::Immutable),
107-
aliases: vec![String::from("array_ndims"), String::from("list_ndims")],
107+
aliases: vec![String::from("list_ndims")],
108108
}
109109
}
110110
}

datafusion/functions-array/src/empty.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ impl ArrayEmpty {
4444
pub fn new() -> Self {
4545
Self {
4646
signature: Signature::array(Volatility::Immutable),
47-
aliases: vec![
48-
"empty".to_string(),
49-
"array_empty".to_string(),
50-
"list_empty".to_string(),
51-
],
47+
aliases: vec!["array_empty".to_string(), "list_empty".to_string()],
5248
}
5349
}
5450
}

datafusion/functions-array/src/except.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl ArrayExcept {
4747
pub fn new() -> Self {
4848
Self {
4949
signature: Signature::any(2, Volatility::Immutable),
50-
aliases: vec!["array_except".to_string(), "list_except".to_string()],
50+
aliases: vec!["list_except".to_string()],
5151
}
5252
}
5353
}

datafusion/functions-array/src/extract.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ impl ArrayElement {
8080
Self {
8181
signature: Signature::array_and_index(Volatility::Immutable),
8282
aliases: vec![
83-
String::from("array_element"),
8483
String::from("array_extract"),
8584
String::from("list_element"),
8685
String::from("list_extract"),
@@ -241,7 +240,7 @@ impl ArraySlice {
241240
pub fn new() -> Self {
242241
Self {
243242
signature: Signature::variadic_any(Volatility::Immutable),
244-
aliases: vec![String::from("array_slice"), String::from("list_slice")],
243+
aliases: vec![String::from("list_slice")],
245244
}
246245
}
247246
}
@@ -513,10 +512,7 @@ impl ArrayPopFront {
513512
pub fn new() -> Self {
514513
Self {
515514
signature: Signature::array(Volatility::Immutable),
516-
aliases: vec![
517-
String::from("array_pop_front"),
518-
String::from("list_pop_front"),
519-
],
515+
aliases: vec![String::from("list_pop_front")],
520516
}
521517
}
522518
}
@@ -591,10 +587,7 @@ impl ArrayPopBack {
591587
pub fn new() -> Self {
592588
Self {
593589
signature: Signature::array(Volatility::Immutable),
594-
aliases: vec![
595-
String::from("array_pop_back"),
596-
String::from("list_pop_back"),
597-
],
590+
aliases: vec![String::from("list_pop_back")],
598591
}
599592
}
600593
}

datafusion/functions-array/src/flatten.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl Flatten {
4747
pub fn new() -> Self {
4848
Self {
4949
signature: Signature::array(Volatility::Immutable),
50-
aliases: vec![String::from("flatten")],
50+
aliases: vec![],
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)