apache / apache/datafusion

Rewrite UDAF reversed expression name

Open
#11,629 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

I think it would be good to eventually move this to a method in `https://github.com/apache/datafusion/pull/11611` though I agree this is good for now. Maybe we can file a ticket to track

_Originally posted by @alamb in https://github.com/apache/datafusion/pull/11611#discussion_r1688699754_

I think we could extend to rewrite the whole expression name, and it could be more straightforward what the name is rewritten

```rust
let mut name = self.name().to_string();
// If the function is changed, we need to reverse order_by clause as well
// i.e. First(a order by b asc null first) -> Last(a order by b desc null last)
if self.fun().name() == reverse_udf.name() {
} else {
replace_order_by_clause(&mut name);
}
replace_fn_name_clause(&mut name, self.fun.name(), reverse_udf.name());
```

Something like
```rust
let mut name = self.name().to_string();
name = self.fun.reverse_name(name)
```

Add `reverse_name` in `AggregateUDFImpl`

```rust
trait AggregateUDFImpl {
fn reverse_name(&self) -> String {
...
}
}
```

Specificially we need to rewrite name for First/Last. For array_agg, the name should be the same.

Contributor guide

Open the contributing guide

Research direction

Start by locating the existing reversed-expression handling that calls replace_order_by_clause and replace_fn_name_clause, then read AggregateUDFImpl and the First, Last, and array_agg implementations. The change is complete when reverse_name centralizes expression-name rewriting, First and Last produce the correct reversed names, and array_agg keeps its name unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.