Skip to content

Conversation

@berkaysynnada
Copy link
Contributor

Which issue does this PR close?

  • Closes #.

Rationale for this change

AggregateFunctionExpr::with_new_expressions()has been implemented. This is useful when updating column indices within the expressions of anAggregateFunctionExpr`.

Additionally, create_window_fn() method has been added to the WindowExpr trait. This provides a convenient way to directly access the underlying window function evaluator.

What changes are included in this PR?

  • AggregateFunctionExpr::with_new_expressions()
  • WindowExpr::create_window_fn()
  • Some derive-Clone's

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate labels Jul 24, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

The code looks good to me @berkaysynnada -- thank you for the contribution.

My only concern is that since there are no tests or paths that use this new code it may be broken as part of some future refactor without knowing. Is there some way to test it (or take advantage of the new APIs?)

order_by_exprs: Vec<Arc<dyn PhysicalExpr>>,
) -> Option<AggregateFunctionExpr> {
None
debug_assert_eq!(args.len(), self.args.len());
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we can return None here if the lengths don't match up so in production builds we don't get wrong results 🤔 Likewise below with the check on order sensitivity

fun: self.fun.clone(),
args,
return_field: Arc::clone(&self.return_field),
// TODO: This name and display fields should be updated after re-write to not mislead
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not 100% sure about this TODO - perhaps the human_display should be changed, but maybe not the name

/// Get the reverse expression of this [WindowExpr].
fn get_reverse_expr(&self) -> Option<Arc<dyn WindowExpr>>;

/// Creates a new instance of the window function evaluator.
Copy link
Contributor

Choose a reason for hiding this comment

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

this is a new API too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this util becomes useful when updating WindowAggState's from deserialized window_fn states. If it seems too specific, I can remove it

@comphead comphead merged commit 9deec2a into apache:main Jul 26, 2025
27 checks passed
adriangb pushed a commit to pydantic/datafusion that referenced this pull request Jul 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants