Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for AggregateExpr, WindowExpr rewrite. #10742

Merged
merged 4 commits into from
May 31, 2024

Conversation

mustafasrepo
Copy link
Contributor

Which issue does this PR close?

Closes #.

Rationale for this change

While working on another PR, in which I implement a new custom rule. I hit a usecase where I want to re-write AggregateExpr, and WindowExpr according to some kind of projection. (For instance , in terms of the schema of the child). In my use case, I find it useful to define an API fn all_expressions(&self) -> (function args, order bys, ..) to return all expressions referred by the aggregate or window function (By the way current fn expressions(&self) API only returns function arguments).

With this API in place, we can update Arc<dyn PhysicalExpr>s, at the outside (such as inside the rule). Then we can use updated expressions to re-write Arc<dyn AggregateExpr> by using following API:

fn with_new_expressions(
    &self,
    _args: Vec<Arc<dyn PhysicalExpr>>,
    _order_by_exprs: Vec<Arc<dyn PhysicalExpr>>,
) -> Option<Arc<dyn AggregateExpr>>

This behaviour, is very similar to the fn expressions(), , fn with_expressions() methods for LogicalPlans.
Also as far as I am aware @berkaysynnada's PR for projection optimization will also require such an API, to be able to check pushdown an aggregate expression or window expression successfully.

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added the physical-expr Physical Expressions label May 31, 2024
Copy link
Member

@waynexia waynexia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those new APIs look good to me, thanks @mustafasrepo

datafusion/physical-expr-common/src/aggregate/mod.rs Outdated Show resolved Hide resolved
/// Rewrites [`AggregateExpr`], with new expressions given. The argument should be consistent
/// with the return value of the [`AggregateExpr::all_expressions`] method.
/// Returns `Some(Arc<dyn AggregateExpr>)` if re-write is supported, otherwise returns `None`.
fn with_new_expressions(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that might be worth considering is that this API forces cloning. However, since everything is Arcd that seems relatively minor. Maybe something to keep in mind for the future.

@alamb alamb merged commit 68f8476 into apache:main May 31, 2024
23 checks passed
@alamb
Copy link
Contributor

alamb commented May 31, 2024

Thanks @mustafasrepo and @waynexia

findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* Initial commit

* Minor changes

* Minor changes

* Update comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants