mightsleep opened a new issue, #11437:
URL: https://github.com/apache/arrow-rs/issues/11437

   ### Is your feature request related to a problem or challenge?
   
   DataFusion evaluates CASE WHEN c THEN expr ELSE literal END with 
kernels::merge, the scalar on one side. merge extends MutableArrayData once per 
row for the scalar side (try_extend(i, 0, 1) in arrow-select/src/merge.rs), 
about 6 ns per row.
   
   ### Describe the solution you'd like
   
   With a scalar side, merge is the transpose of filter: fill the output with 
the scalar and write the array side to the mask's set bits (set_indices). The 
validity has closed forms: no null buffer when neither side has nulls, the mask 
itself for a NULL scalar, otherwise (scalar valid ? !mask : 0) | expand(array 
validity, mask) in the same loop. Utf8View works the same way on the views, 
sharing the array's buffers. DataFusion's own scatter 
(physical-expr-common/src/utils.rs) already does this for a CASE without ELSE.
   
   Prototype numbers:
   - kernel, TPC-H SF1 CASE inputs (Q14, Q8, Decimal128): 6 ns to 0.2 ns per row
   - DataFusion main, 10M ClickBench rows, one thread: SUM(CASE WHEN "IsMobile" 
= 1 THEN "ResolutionWidth" ELSE 0 END) 90 ms to 42 ms, COUNT(DISTINCT CASE ... 
ELSE 'desktop' END) 114 ms to 58 ms
   - dense masks with long runs gain little; there the existing run copy stays
   
   I plan to open a PR for primitive and view types, benchmarks first.
   
   ### Describe alternatives you've considered
   
   Interleave with running counters, as zip does since #10368: about 2.6 ns per 
row and slower than today on long runs.
   
   ### Additional context
   
   _No response_


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to