You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "2010YOUY01 (via GitHub)" <gi...@apache.org> on 2026/08/31 06:19:29 UTC
[PR] chore: collapse duplicated branches that differ by one value [datafusion]
2010YOUY01 opened a new pull request, #24814:
URL: https://github.com/apache/datafusion/pull/24814
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
- Closes #.
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
Please explain the problem you are trying to solve in terms of the user-visible
behavior, rather than the implementation.
For example, "The code in `foo.rs` doesn't handle nulls" is a symptom of the
implementation. "COUNT(DISTINCT) returns wrong results when the column contains
nulls" is the user-visible problem.
-->
The following code snippet demonstrates the refactor idea, I find the second version is more eye-friendly, especially when the struct gets large.
```
// before
if foo {
Config { a: v1, b: v2, c: v3 }
} else {
Config { a: v1, b: v2, c: v4 }
}
// after
let c = if foo { v3 } else { v4 };
Config { a: v1, b: v2, c }
```
This PR applies this idea to safe locations across the codebase.
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here, but it is sometimes worth providing a summary of the individual changes in this PR.
-->
## What is the testing strategy for this PR?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
Briefly describe how this PR is tested, and point to the specific tests you added. For example: 'This new feature is covered by the `sqllogictest` cases added in `foo.slt`'.
If this PR does not add tests, explain why. For example, if the change is already covered by existing tests, please mention it.
You should also check the `codecov` bot reply on this PR to confirm the changed code is exercised.
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
If there are any breaking changes to public APIs, please add the `api change` label.
-->
--
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] chore: collapse duplicated branches that differ by one value [datafusion]
Posted by "getChan (via GitHub)" <gi...@apache.org>.
getChan commented on code in PR #24814:
URL: https://github.com/apache/datafusion/pull/24814#discussion_r3894749047
##########
datafusion/functions-aggregate/src/min_max/min_max_struct.rs:
##########
@@ -83,21 +83,11 @@ impl GroupsAccumulator for MinMaxStructAccumulator {
matches!(partial_cmp_struct(a, b), Some(Ordering::Greater))
}
- if self.is_min {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_min,
- )
- } else {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_max,
- )
- }
+ let cmp: fn(&StructArray, &StructArray) -> bool =
+ if self.is_min { struct_min } else { struct_max };
+
+ self.inner
+ .update_batch(array.as_struct(), group_indices, total_num_groups, cmp)
}
fn evaluate(&mut self, emit_to: EmitTo) -> Result<ArrayRef> {
Review Comment:
nit: This refactoring coerces `struct_min` / `struct_max` to a function pointer. Since `cmp` is called from the per-row loop in `MinMaxStructState::update_batch`, this is a hot path where even small overhead can accumulate.
I compared the release LLVM IR locally: the updated version selects a function pointer and invokes it indirectly inside the loop, whereas the original version produces separate MIN/MAX loops. I also ran a small local release benchmark for a single-field `STRUCT` MAX aggregation; the median changed from 1.20s to 1.46s (+22%).
The original code is a little more verbose, but would you mind keeping the two branches here to preserve static dispatch?
--
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] chore: collapse duplicated branches that differ by one value [datafusion]
Posted by "getChan (via GitHub)" <gi...@apache.org>.
getChan commented on code in PR #24814:
URL: https://github.com/apache/datafusion/pull/24814#discussion_r3894749047
##########
datafusion/functions-aggregate/src/min_max/min_max_struct.rs:
##########
@@ -83,21 +83,11 @@ impl GroupsAccumulator for MinMaxStructAccumulator {
matches!(partial_cmp_struct(a, b), Some(Ordering::Greater))
}
- if self.is_min {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_min,
- )
- } else {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_max,
- )
- }
+ let cmp: fn(&StructArray, &StructArray) -> bool =
+ if self.is_min { struct_min } else { struct_max };
+
+ self.inner
+ .update_batch(array.as_struct(), group_indices, total_num_groups, cmp)
}
fn evaluate(&mut self, emit_to: EmitTo) -> Result<ArrayRef> {
Review Comment:
nit: This refactoring coerces `struct_min` / `struct_max` to a function pointer. Since `cmp` is called from the per-row loop in `MinMaxStructState::update_batch`, this is a hot path where even small overhead can accumulate.
I compared the release LLVM IR locally: the updated version selects a function pointer and invokes it indirectly inside the loop, whereas the original version produces separate MIN/MAX loops.
The original code is a little more verbose, but would you mind keeping the two branches here to preserve static dispatch?
--
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] chore: collapse duplicated branches that differ by one value [datafusion]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #24814:
URL: https://github.com/apache/datafusion/pull/24814#issuecomment-5474713571
## [Codecov](https://app.codecov.io/gh/apache/datafusion/pull/24814?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `84.00000%` with `12 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 81.52%. Comparing base ([`e4cf35c`](https://app.codecov.io/gh/apache/datafusion/commit/e4cf35cbca92e6fda855d5eac4104b47e0e600e9?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`f5a7cb2`](https://app.codecov.io/gh/apache/datafusion/commit/f5a7cb25610182ed448e08d22a883da825484118?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 3 commits behind head on main.
| [Files with missing lines](https://app.codecov.io/gh/apache/datafusion/pull/24814?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [datafusion/expr/src/expr.rs](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&filepath=datafusion%2Fexpr%2Fsrc%2Fexpr.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9leHByLnJz) | 50.00% | [6 Missing :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/expr/src/logical\_plan/builder.rs](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&filepath=datafusion%2Fexpr%2Fsrc%2Flogical_plan%2Fbuilder.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9leHByL3NyYy9sb2dpY2FsX3BsYW4vYnVpbGRlci5ycw==) | 83.33% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/proto/src/logical\_plan/to\_proto.rs](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&filepath=datafusion%2Fproto%2Fsrc%2Flogical_plan%2Fto_proto.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9wcm90by9zcmMvbG9naWNhbF9wbGFuL3RvX3Byb3RvLnJz) | 89.47% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [datafusion/sql/src/unparser/expr.rs](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&filepath=datafusion%2Fsql%2Fsrc%2Funparser%2Fexpr.rs&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZGF0YWZ1c2lvbi9zcWwvc3JjL3VucGFyc2VyL2V4cHIucnM=) | 84.61% | [0 Missing and 2 partials :warning: ](https://app.codecov.io/gh/apache/datafusion/pull/24814?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #24814 +/- ##
=======================================
Coverage 81.52% 81.52%
=======================================
Files 1123 1123
Lines 406148 406205 +57
Branches 406148 406205 +57
=======================================
+ Hits 331124 331176 +52
- Misses 55659 55661 +2
- Partials 19365 19368 +3
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/datafusion/pull/24814?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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] chore: collapse duplicated branches that differ by one value [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 merged PR #24814:
URL: https://github.com/apache/datafusion/pull/24814
--
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] chore: collapse duplicated branches that differ by one value [datafusion]
Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #24814:
URL: https://github.com/apache/datafusion/pull/24814#discussion_r3894886845
##########
datafusion/functions-aggregate/src/min_max/min_max_struct.rs:
##########
@@ -83,21 +83,11 @@ impl GroupsAccumulator for MinMaxStructAccumulator {
matches!(partial_cmp_struct(a, b), Some(Ordering::Greater))
}
- if self.is_min {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_min,
- )
- } else {
- self.inner.update_batch(
- array.as_struct(),
- group_indices,
- total_num_groups,
- struct_max,
- )
- }
+ let cmp: fn(&StructArray, &StructArray) -> bool =
+ if self.is_min { struct_min } else { struct_max };
+
+ self.inner
+ .update_batch(array.as_struct(), group_indices, total_num_groups, cmp)
}
fn evaluate(&mut self, emit_to: EmitTo) -> Result<ArrayRef> {
Review Comment:
good catch, reverted
--
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