Repository navigation
refactor: share a single pad kernel between lpad and rpad - #26367
shazilkhan wants to merge 5 commits into
Conversation
ea011db to
7c5c7d7
Compare
neilconway
left a comment
There was a problem hiding this comment.
Thanks @shazilkhan! Overall this looks very reasonable. Can you move the new tests to SLT where possible?
It would be easier to review this PR if you had sent the refactor as a separate PR from optimizations, benchmark changes, or test enhancements. I don't think it's worth redoing the work now but please consider that for the future.
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { |
There was a problem hiding this comment.
Most (or all?) of these tests can be done in SLT, which should be preferred when possible.
|
run benchmark unicode_expressions |
|
🤖 Benchmark running (GKE) | trigger CPU Details (lscpu)Comparing shared-pad-kernel (7c5c7d7) to c113e29 diff Run configurationrun benchmark unicode_expressions
env:
BENCH_FILTER: "pad"
baseline:
ref: "c113e2989fee2355afcfca69a3173fdefe7fee79"Results will be posted here when complete File an issue against this benchmark runner |
|
🤖 Benchmark completed (GKE) | trigger Instance: Comparing shared-pad-kernel (7c5c7d7) to c113e29 diff Run configurationrun benchmark unicode_expressions
env:
BENCH_FILTER: "pad"
baseline:
ref: "c113e2989fee2355afcfca69a3173fdefe7fee79"CPU Details (lscpu)Details
Resource Usageunicode_expressions — base (merge-base)
unicode_expressions — branch
File an issue against this benchmark runner |
Per review feedback, the pad.rs unit tests are all expressible in SQL, so they now live in string_literal.slt next to the other lpad/rpad tests.
|
Thanks for the review and for running the benchmarks @neilconway!
|
|
Updated the branch with main, which also clears the semver warning (the |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26367 +/- ##
==========================================
- Coverage 82.94% 82.94% -0.01%
==========================================
Files 1156 1157 +1
Lines 458581 458276 -305
Branches 458581 458276 -305
==========================================
- Hits 380382 380125 -257
+ Misses 55145 55103 -42
+ Partials 23054 23048 -6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Which issue does this PR close?
Rationale for this change
lpad and rpad had four copies of the same per-row padding loop, plus two copies of the scalar fast path. The only real difference between them was whether the fill gets written before or after the string.
What changes are included in this PR?
unicode/pad.rswith a single kernel, generic over aPadSidetrait (LeftPad/RightPad, same idea asLeftRightSlicerincommon.rs).lpad.rsandrpad.rsare now thin wrappers with just the docs and tests." "as the fill, so the second loop is gone.parse_target_lenreplaces the six copies of thei32::MAX/ negative length check. Error text is unchanged.Two things came out of benchmarking:
#[cold]function fixed that.%per char. That's where the speedup below comes from.I also added
no fillcases to the pad benchmarks (first commit). None of the existing cases covered a 2-arg call with a length column, which is the path this changes the most.What is the testing strategy for this PR?
Existing lpad/rpad unit tests and sqllogictests pass unchanged. I added tests in
pad.rsthat pass array arguments to both functions, since most of the existing ones go through the scalar fast path: no fill, fill, nulls, zero length, truncation, string view input, a partial multi-char unicode fill (rpad('josé', 6, 'ñéx')), and the too-large length error.Benchmarks
cargo bench -p datafusion-functions --features unicode_expressions --bench unicode_expressions -- "pad size=", main vs this branch, run back to back on the same machine:Happy to re-run anything if someone wants different numbers.
Are there any user-facing changes?
No.
Separately, I found that a negative length coming from a column panics on main (
pad_data_capacitydoeslen as usize). That's not part of this PR, and I'll open its own issue.