Skip to content

Commit 08e19f4

Browse files
authored
Remove redundant upper case aliases for median, first_value and last_value (#10696)
* change udaf name to lowercase * enhance test for duplicate function name * fix test * fix tests * remove redundant alias field
1 parent 156a525 commit 08e19f4

File tree

10 files changed

+124
-130
lines changed

10 files changed

+124
-130
lines changed

datafusion/functions-aggregate/src/first_last.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ make_udaf_expr_and_func!(
4949

5050
pub struct FirstValue {
5151
signature: Signature,
52-
aliases: Vec<String>,
5352
requirement_satisfied: bool,
5453
}
5554

@@ -72,7 +71,6 @@ impl Default for FirstValue {
7271
impl FirstValue {
7372
pub fn new() -> Self {
7473
Self {
75-
aliases: vec![String::from("first_value")],
7674
signature: Signature::one_of(
7775
vec![
7876
// TODO: we can introduce more strict signature that only numeric of array types are allowed
@@ -97,7 +95,7 @@ impl AggregateUDFImpl for FirstValue {
9795
}
9896

9997
fn name(&self) -> &str {
100-
"FIRST_VALUE"
98+
"first_value"
10199
}
102100

103101
fn signature(&self) -> &Signature {
@@ -144,7 +142,7 @@ impl AggregateUDFImpl for FirstValue {
144142
}
145143

146144
fn aliases(&self) -> &[String] {
147-
&self.aliases
145+
&[]
148146
}
149147

150148
fn with_beneficial_ordering(
@@ -349,7 +347,6 @@ make_udaf_expr_and_func!(
349347

350348
pub struct LastValue {
351349
signature: Signature,
352-
aliases: Vec<String>,
353350
requirement_satisfied: bool,
354351
}
355352

@@ -372,7 +369,6 @@ impl Default for LastValue {
372369
impl LastValue {
373370
pub fn new() -> Self {
374371
Self {
375-
aliases: vec![String::from("last_value")],
376372
signature: Signature::one_of(
377373
vec![
378374
// TODO: we can introduce more strict signature that only numeric of array types are allowed
@@ -397,7 +393,7 @@ impl AggregateUDFImpl for LastValue {
397393
}
398394

399395
fn name(&self) -> &str {
400-
"LAST_VALUE"
396+
"last_value"
401397
}
402398

403399
fn signature(&self) -> &Signature {
@@ -449,7 +445,7 @@ impl AggregateUDFImpl for LastValue {
449445
}
450446

451447
fn aliases(&self) -> &[String] {
452-
&self.aliases
448+
&[]
453449
}
454450

455451
fn with_beneficial_ordering(

datafusion/functions-aggregate/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ mod tests {
109109
let mut names = HashSet::new();
110110
for func in all_default_aggregate_functions() {
111111
assert!(
112-
names.insert(func.name().to_string()),
112+
names.insert(func.name().to_string().to_lowercase()),
113113
"duplicate function name: {}",
114114
func.name()
115115
);
116116
for alias in func.aliases() {
117117
assert!(
118-
names.insert(alias.to_string()),
118+
names.insert(alias.to_string().to_lowercase()),
119119
"duplicate function name: {}",
120120
alias
121121
);

datafusion/functions-aggregate/src/median.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ make_udaf_expr_and_func!(
5858
/// result, but if cardinality is low then memory usage will also be lower.
5959
pub struct Median {
6060
signature: Signature,
61-
aliases: Vec<String>,
6261
}
6362

6463
impl Debug for Median {
@@ -79,7 +78,6 @@ impl Default for Median {
7978
impl Median {
8079
pub fn new() -> Self {
8180
Self {
82-
aliases: vec!["median".to_string()],
8381
signature: Signature::numeric(1, Volatility::Immutable),
8482
}
8583
}
@@ -91,7 +89,7 @@ impl AggregateUDFImpl for Median {
9189
}
9290

9391
fn name(&self) -> &str {
94-
"MEDIAN"
92+
"median"
9593
}
9694

9795
fn signature(&self) -> &Signature {
@@ -152,7 +150,7 @@ impl AggregateUDFImpl for Median {
152150
}
153151

154152
fn aliases(&self) -> &[String] {
155-
&self.aliases
153+
&[]
156154
}
157155
}
158156

datafusion/functions-array/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,13 @@ mod tests {
168168
let mut names = HashSet::new();
169169
for func in all_default_array_functions() {
170170
assert!(
171-
names.insert(func.name().to_string()),
171+
names.insert(func.name().to_string().to_lowercase()),
172172
"duplicate function name: {}",
173173
func.name()
174174
);
175175
for alias in func.aliases() {
176176
assert!(
177-
names.insert(alias.to_string()),
177+
names.insert(alias.to_string().to_lowercase()),
178178
"duplicate function name: {}",
179179
alias
180180
);

datafusion/functions/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ mod tests {
191191
let mut names = HashSet::new();
192192
for func in all_default_functions() {
193193
assert!(
194-
names.insert(func.name().to_string()),
194+
names.insert(func.name().to_string().to_lowercase()),
195195
"duplicate function name: {}",
196196
func.name()
197197
);
198198
for alias in func.aliases() {
199199
assert!(
200-
names.insert(alias.to_string()),
200+
names.insert(alias.to_string().to_lowercase()),
201201
"duplicate function name: {}",
202202
alias
203203
);

datafusion/optimizer/src/replace_distinct_aggregate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ mod tests {
201201
)?
202202
.build()?;
203203

204-
let expected = "Projection: FIRST_VALUE(test.b) ORDER BY [test.a DESC NULLS FIRST, test.c ASC NULLS LAST] AS b\
204+
let expected = "Projection: first_value(test.b) ORDER BY [test.a DESC NULLS FIRST, test.c ASC NULLS LAST] AS b\
205205
\n Sort: test.a DESC NULLS FIRST\
206-
\n Aggregate: groupBy=[[test.a]], aggr=[[FIRST_VALUE(test.b) ORDER BY [test.a DESC NULLS FIRST, test.c ASC NULLS LAST]]]\
206+
\n Aggregate: groupBy=[[test.a]], aggr=[[first_value(test.b) ORDER BY [test.a DESC NULLS FIRST, test.c ASC NULLS LAST]]]\
207207
\n TableScan: test";
208208

209209
assert_optimized_plan_eq(

datafusion/sqllogictest/test_files/aggregate.slt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -879,15 +879,15 @@ query TT
879879
explain select median(distinct c) from t;
880880
----
881881
logical_plan
882-
01)Projection: MEDIAN(alias1) AS MEDIAN(DISTINCT t.c)
883-
02)--Aggregate: groupBy=[[]], aggr=[[MEDIAN(alias1)]]
882+
01)Projection: median(alias1) AS median(DISTINCT t.c)
883+
02)--Aggregate: groupBy=[[]], aggr=[[median(alias1)]]
884884
03)----Aggregate: groupBy=[[t.c AS alias1]], aggr=[[]]
885885
04)------TableScan: t projection=[c]
886886
physical_plan
887-
01)ProjectionExec: expr=[MEDIAN(alias1)@0 as MEDIAN(DISTINCT t.c)]
888-
02)--AggregateExec: mode=Final, gby=[], aggr=[MEDIAN(alias1)]
887+
01)ProjectionExec: expr=[median(alias1)@0 as median(DISTINCT t.c)]
888+
02)--AggregateExec: mode=Final, gby=[], aggr=[median(alias1)]
889889
03)----CoalescePartitionsExec
890-
04)------AggregateExec: mode=Partial, gby=[], aggr=[MEDIAN(alias1)]
890+
04)------AggregateExec: mode=Partial, gby=[], aggr=[median(alias1)]
891891
05)--------AggregateExec: mode=FinalPartitioned, gby=[alias1@0 as alias1], aggr=[]
892892
06)----------CoalesceBatchesExec: target_batch_size=8192
893893
07)------------RepartitionExec: partitioning=Hash([alias1@0], 4), input_partitions=4
@@ -5024,12 +5024,12 @@ query TT
50245024
explain select first_value(c1 order by c3 desc) from convert_first_last_table;
50255025
----
50265026
logical_plan
5027-
01)Aggregate: groupBy=[[]], aggr=[[FIRST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 DESC NULLS FIRST]]]
5027+
01)Aggregate: groupBy=[[]], aggr=[[first_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 DESC NULLS FIRST]]]
50285028
02)--TableScan: convert_first_last_table projection=[c1, c3]
50295029
physical_plan
5030-
01)AggregateExec: mode=Final, gby=[], aggr=[FIRST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 DESC NULLS FIRST]]
5030+
01)AggregateExec: mode=Final, gby=[], aggr=[first_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 DESC NULLS FIRST]]
50315031
02)--CoalescePartitionsExec
5032-
03)----AggregateExec: mode=Partial, gby=[], aggr=[LAST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 ASC NULLS LAST]]
5032+
03)----AggregateExec: mode=Partial, gby=[], aggr=[last_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c3 ASC NULLS LAST]]
50335033
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
50345034
05)--------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/convert_first_last.csv]]}, projection=[c1, c3], output_orderings=[[c1@0 ASC NULLS LAST], [c3@1 ASC NULLS LAST]], has_header=true
50355035

@@ -5038,11 +5038,11 @@ query TT
50385038
explain select last_value(c1 order by c2 asc) from convert_first_last_table;
50395039
----
50405040
logical_plan
5041-
01)Aggregate: groupBy=[[]], aggr=[[LAST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 ASC NULLS LAST]]]
5041+
01)Aggregate: groupBy=[[]], aggr=[[last_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 ASC NULLS LAST]]]
50425042
02)--TableScan: convert_first_last_table projection=[c1, c2]
50435043
physical_plan
5044-
01)AggregateExec: mode=Final, gby=[], aggr=[LAST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 ASC NULLS LAST]]
5044+
01)AggregateExec: mode=Final, gby=[], aggr=[last_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 ASC NULLS LAST]]
50455045
02)--CoalescePartitionsExec
5046-
03)----AggregateExec: mode=Partial, gby=[], aggr=[FIRST_VALUE(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 DESC NULLS FIRST]]
5046+
03)----AggregateExec: mode=Partial, gby=[], aggr=[first_value(convert_first_last_table.c1) ORDER BY [convert_first_last_table.c2 DESC NULLS FIRST]]
50475047
04)------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
50485048
05)--------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/datafusion/core/tests/data/convert_first_last.csv]]}, projection=[c1, c2], output_orderings=[[c1@0 ASC NULLS LAST], [c2@1 DESC]], has_header=true

datafusion/sqllogictest/test_files/distinct_on.slt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ query TT
8989
EXPLAIN SELECT DISTINCT ON (c1) c3, c2 FROM aggregate_test_100 ORDER BY c1, c3;
9090
----
9191
logical_plan
92-
01)Projection: FIRST_VALUE(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST] AS c3, FIRST_VALUE(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST] AS c2
92+
01)Projection: first_value(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST] AS c3, first_value(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST] AS c2
9393
02)--Sort: aggregate_test_100.c1 ASC NULLS LAST
94-
03)----Aggregate: groupBy=[[aggregate_test_100.c1]], aggr=[[FIRST_VALUE(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], FIRST_VALUE(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]]
94+
03)----Aggregate: groupBy=[[aggregate_test_100.c1]], aggr=[[first_value(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], first_value(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]]
9595
04)------TableScan: aggregate_test_100 projection=[c1, c2, c3]
9696
physical_plan
97-
01)ProjectionExec: expr=[FIRST_VALUE(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]@1 as c3, FIRST_VALUE(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]@2 as c2]
97+
01)ProjectionExec: expr=[first_value(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]@1 as c3, first_value(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]@2 as c2]
9898
02)--SortPreservingMergeExec: [c1@0 ASC NULLS LAST]
9999
03)----SortExec: expr=[c1@0 ASC NULLS LAST], preserve_partitioning=[true]
100-
04)------AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[FIRST_VALUE(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], FIRST_VALUE(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]
100+
04)------AggregateExec: mode=FinalPartitioned, gby=[c1@0 as c1], aggr=[first_value(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], first_value(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]
101101
05)--------CoalesceBatchesExec: target_batch_size=8192
102102
06)----------RepartitionExec: partitioning=Hash([c1@0], 4), input_partitions=4
103-
07)------------AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[FIRST_VALUE(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], FIRST_VALUE(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]
103+
07)------------AggregateExec: mode=Partial, gby=[c1@0 as c1], aggr=[first_value(aggregate_test_100.c3) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST], first_value(aggregate_test_100.c2) ORDER BY [aggregate_test_100.c1 ASC NULLS LAST, aggregate_test_100.c3 ASC NULLS LAST]]
104104
08)--------------RepartitionExec: partitioning=RoundRobinBatch(4), input_partitions=1
105105
09)----------------CsvExec: file_groups={1 group: [[WORKSPACE_ROOT/testing/data/csv/aggregate_test_100.csv]]}, projection=[c1, c2, c3], has_header=true
106106

0 commit comments

Comments
 (0)