timsaucer commented on issue #6747:
URL: https://github.com/apache/datafusion/issues/6747#issuecomment-2236257604
I've started looking at this and coming up against one blocker that prevents
just following the exact pattern.
My first thought was to implement a trait like
```
pub trait WindowExt {
fn order_by(self, order_by: Vec<Expr>) -> WindowBuilder;
fn partition_by(self, partitions: Vec<Expr>) -> WindowBuilder;
fn window_frame(self, window_frame: WindowFrame) -> WindowBuilder;
fn null_treatment(self, null_treatment: NullTreatment) -> WindowBuilder;
}
```
The problem with this is that we would have two traits implemented on `Expr`
that have two identical function names, `order_by` and `null_treatment`. I
*could* give them different names, but that isn't a great user experience. Plus
there's the fact that all aggregate functions can be used as window functions.
My current thinking is that instead of doing this, I should rename
`AggregateExt` to something like `ExprExt`. This trait would have something like
```
pub trait ExprExt {
fn order_by(self, order_by: Vec<Expr>) -> ExprBuilder;
fn filter(self, filter: Expr) -> ExprBuilder;
fn distinct(self) -> ExprBuilder;
fn partition_by(self, partitions: Vec<Expr>) -> ExprBuilder;
fn window_frame(self, window_frame: WindowFrame) -> ExprBuilder;
fn null_treatment(self, null_treatment: NullTreatment) -> ExprBuilder;
}
```
Then the `ExprBuilder` would do something like
```
pub struct ExprBuilder {
expr_data: ExprBuilderData,
order_by: Option<Vec<Expr>>,
filter: Option<Expr>,
distinct: bool,
null_treatment: Option<NullTreatment>,
}
```
And finally
```
enum ExprBuilderData {
AggregateBuilderData(AggregateFunction),
WindowBuilderData(WindowFunction),
CaseBuilderData(Case),
None,
}
```
I haven't dug too much deeper into it, but these are my initial design
ideas. @jayzhan211 and @alamb what do you think?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]