Remove `Alias` from `Expr`
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
Currently a named expression / alias can be encoded by wrapping an existing `Expr` in an `Expr::Alias`.
However, this has some side effects:
* We can encode expressions that don't make sense, such as `(1 + 1 AS x) AS y` or `(1 AS X) + (1 AS Y)` (in SQL it's disallowed by the parser, but it's just to show it is possible to do this in the DataFrame API or the raw API. In dataframes we could do things like `expr.alias("x").alias("y")`.
* Code dealing with `Expr` always have to deal with the `Alias` case, even when it doesn't care. This could lead to more complex code or even subtle bugs.
**Describe the solution you'd like**
* Create a new struct, `NamedExpr` that is used to refer to a named expression
```rust
struct NamedExpr {
/// Alias or generated name
name: String,
/// The expression
expr: Expr,
}
```
* The `NamedExpr` now can be used inside projections, aggregates, etc.
* The function `alias` on `DataFrame` should return an `NamedExpr`
* Add an `impl From for NamedExpr` that generates a name.
* Some functions can accept Into to keep being ergonomic to use.
**Describe alternatives you've considered**
**Additional context**
Contributor guide
Research direction
Start by tracing Expr and its existing Alias handling, then review the projection and aggregate APIs that consume expressions. Define the NamedExpr boundary described in the issue, including generated names and alias conversion, and update the affected APIs so named expressions are accepted without allowing nested or invalid aliases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100