You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "Omega359 (via GitHub)" <gi...@apache.org> on 2025/02/13 16:11:08 UTC
[PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Omega359 opened a new pull request, #14653:
URL: https://github.com/apache/datafusion/pull/14653
## Which issue does this PR close?
- Part of #14563, related to https://github.com/apache/datafusion/pull/14636
```
with_column_10 time: [3.6602 ms 3.8457 ms 4.2130 ms]
with_column_100 time: [34.874 ms 35.979 ms 38.018 ms]
with_column_200 time: [183.49 ms 187.29 ms 191.65 ms]
```
If there is any dataframe expert here I would love a review of my assumptions. As noted in https://github.com/apache/datafusion/issues/14563#issuecomment-2654798363
> My thinking for the changes in my current branch was that any 'new' Expr (parameter to with_column, with_column_renamed, etc) would go through the normalization, everything else I would like to think would already have been normalized or else how would it be in the DataFrame? What worries me is that I don't know if that assumption is correct or not.
## Rationale for this change
Improve performance for with_column and with_column_renamed dataframe functions.
## What changes are included in this PR?
Code
## Are these changes tested?
Existing tests
## Are there any user-facing changes?
No.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #14653:
URL: https://github.com/apache/datafusion/pull/14653
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#discussion_r1970468759
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -1612,13 +1621,33 @@ pub fn union_by_name(
pub fn project(
plan: LogicalPlan,
expr: impl IntoIterator<Item = impl Into<Expr>>,
+) -> Result<LogicalPlan> {
+ project_with_validation(plan, expr.into_iter().map(|e| (e, true)))
+}
+
+/// Create Projection. Similar to project except that the expressions
+/// passed in have a flag to indicate if that expression requires
+/// validation (normalize & columnize) (true) or not (false)
+/// # Errors
+/// This function errors under any of the following conditions:
+/// * Two or more expressions have the same name
+/// * An invalid expression is used (e.g. a `sort` expression)
+pub fn project_with_validation(
Review Comment:
No it doesn't, fixed.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2661642119
I've made some changes locally where I test to see if the existing plan is a projection but I realized that I can't just rely on that either as the plan could possibly have been manually made then a DataFrame wrapped around it and the with_column function called.
For my approach to work I would need a way to strongly guarantee that the last projection that was made was done via the project(..) function in the builder where the normalization/columnization is guaranteed to have happened. I'm not sure right now how to do that
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 closed pull request #14653: Dataframe with_column and with_column_renamed performance improvements
URL: https://github.com/apache/datafusion/pull/14653
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on code in PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#discussion_r1970633135
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -183,6 +183,8 @@ pub struct DataFrame {
// Box the (large) SessionState to reduce the size of DataFrame on the stack
session_state: Box<SessionState>,
plan: LogicalPlan,
+ // whether we can skip validation for projection ops
Review Comment:
Updated, please review text when you have a chance.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "timsaucer (via GitHub)" <gi...@apache.org>.
timsaucer commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2659395911
I suspect you're right about that assumption not being correct. I've dug through a bit, but I'd probably need to write up a unit test to verify.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2663930834
```
with_column_10 time: [6.1112 ms 6.2616 ms 6.4226 ms]
change: [+18.276% +23.739% +29.703%] (p = 0.00 < 0.05)
with_column_100 time: [41.379 ms 54.353 ms 66.683 ms]
change: [+18.326% +33.842% +55.521%] (p = 0.00 < 0.05)
with_column_200 time: [198.59 ms 209.45 ms 224.33 ms]
change: [-1.0194% +5.1906% +12.830%] (p = 0.20 > 0.05)
with_column_500 time: [3.5914 s 3.7758 s 4.0800 s]
change: [-13.580% -6.5454% +2.3214%] (p = 0.16 > 0.05)
No change in performance detected.
```
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2687670078
Thanks again @Omega359
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#discussion_r1970165386
##########
datafusion/core/src/dataframe/mod.rs:
##########
@@ -183,6 +183,8 @@ pub struct DataFrame {
// Box the (large) SessionState to reduce the size of DataFrame on the stack
session_state: Box<SessionState>,
plan: LogicalPlan,
+ // whether we can skip validation for projection ops
Review Comment:
Could you add some additional comments here about what circumstances permit validation to be skipped?
##########
datafusion/core/benches/dataframe.rs:
##########
@@ -68,8 +67,7 @@ fn run(column_count: u32, ctx: Arc<SessionContext>) {
}
fn criterion_benchmark(c: &mut Criterion) {
- // 500 takes far too long right now
- for column_count in [10, 100, 200 /* 500 */] {
+ for column_count in [10, 100, 200, 500] {
Review Comment:
🎉
##########
datafusion/expr/src/logical_plan/builder.rs:
##########
@@ -1612,13 +1621,33 @@ pub fn union_by_name(
pub fn project(
plan: LogicalPlan,
expr: impl IntoIterator<Item = impl Into<Expr>>,
+) -> Result<LogicalPlan> {
+ project_with_validation(plan, expr.into_iter().map(|e| (e, true)))
+}
+
+/// Create Projection. Similar to project except that the expressions
+/// passed in have a flag to indicate if that expression requires
+/// validation (normalize & columnize) (true) or not (false)
+/// # Errors
+/// This function errors under any of the following conditions:
+/// * Two or more expressions have the same name
+/// * An invalid expression is used (e.g. a `sort` expression)
+pub fn project_with_validation(
Review Comment:
does this need to be `pub`? It seems like it is an implementation detail of
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2676370277
This should be ready for review.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Dataframe with_column and with_column_renamed performance improvements [datafusion]
Posted by "Omega359 (via GitHub)" <gi...@apache.org>.
Omega359 commented on PR #14653:
URL: https://github.com/apache/datafusion/pull/14653#issuecomment-2657304910
After spending more time reviewing the dataframe and logical plan code I have a feeling that my assumption is in fact not correct and that a dataframe can indeed have a plan that is not normalized/columnized prior to with_column being called. Joins, window, aggregate, are possible examples.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org