You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/07/28 18:04:18 UTC
[I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
andygrove opened a new issue, #5091:
URL: https://github.com/apache/datafusion-comet/issues/5091
### What is the problem the feature request solves?
A number of small hand-rolled element loops re-implement work that arrow kernels or arity helpers already provide, with identical results and null handling:
- `native/spark-expr/src/conversion_funcs/numeric.rs` (`spark_cast_decimal_to_boolean`): per-row builder loop emitting `!value.is_zero()`. Replaceable with `arrow::compute::kernels::cmp::neq` against a zero-decimal `Scalar` of the same precision/scale (arrow's cast does not support Decimal-to-Boolean, but the comparison kernel is exactly equivalent and infallible).
- `native/spark-expr/src/array_funcs/array_insert.rs`: builds validity masks by collecting `(0..num_rows).map(|row| arr.is_valid(row))` into `Vec<bool>` twice. Replaceable with `boolean::is_not_null` and `boolean::and` at the bitmap level.
- `native/spark-expr/src/kernels/temporal.rs` (`DAYS_TO_UNIX_EPOCH` + `days_to_date`): re-derives days-since-epoch to `NaiveDate` with a hand-maintained epoch constant. Replaceable with `Date32Type::to_naive_date_opt`, already used elsewhere in the crate.
- `native/spark-expr/src/math_funcs/pow.rs`: four-way scalar/array match with iterator zip/map/collect loops. The array/array arm is exactly `arity::binary` over the existing `spark_powf` closure; the dispatch can collapse via the Datum idiom already used in `modulo_expr.rs`.
- `native/spark-expr/src/math_funcs/internal/make_decimal.rs`: per-row `Decimal128Builder` loop. Replaceable with `unary_opt` (note: not arrow's Int64-to-Decimal cast, which would rescale; MakeDecimal reinterprets the unscaled value).
- `native/spark-expr/src/agg_funcs/covariance.rs` (`update_batch`/`retract_batch`): fragile dual-array null re-synchronization using `iter().flatten()` plus `is_valid(i)`. The sibling `correlation.rs` already shows the clean idiom: `and(is_not_null(a), is_not_null(b))` + `filter`, then iterate dense values.
- `native/core/src/execution/columnar_to_row.rs` (`maybe_cast_to_schema_type`): Int32/Int64-to-Decimal128 reinterpretation via `iter().map().collect()`. Replaceable with `arity::unary`, which reuses the null buffer zero-copy (arrow's cast is not usable here since it would rescale the value).
### Describe the potential solution
Apply the listed kernel/arity replacements. Each is behavior-preserving; most also remove per-row branching or allocation.
### Additional context
These are grouped because each change is small; they can land as one PR or a few. Found during an audit of native code that replicates existing arrow-rs kernels.
--
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.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: [I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on issue #5091:
URL: https://github.com/apache/datafusion-comet/issues/5091#issuecomment-5870681924
#5193 and #5367 replaced five of the seven loops here: decimal to boolean, the array_insert validity masks, pow, make_decimal and the columnar_to_row decimal reinterpretation. The other two were tried in #5367 and reverted because they regressed (to_naive_date_opt rebuilds the epoch per row in days_to_date, and the covariance filter allocates two arrays per batch). Closing this; the zip-based cleanup of the covariance null sync can go in its own PR if anyone wants it.
--
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: [I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed issue #5091: Replace small hand-rolled element loops with arrow kernels and arity helpers
URL: https://github.com/apache/datafusion-comet/issues/5091
--
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: [I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on issue #5091:
URL: https://github.com/apache/datafusion-comet/issues/5091#issuecomment-5143862264
take
--
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: [I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on issue #5091:
URL: https://github.com/apache/datafusion-comet/issues/5091#issuecomment-5303040304
Tried and reverted (bench regressed):
- temporal.rs::days_to_date → Date32Type::to_naive_date_opt. date_trunc regressed +15% to +29% on three of
four shapes because chrono::NaiveDate::from_ymd_opt(1970, 1, 1).unwrap() is not const, so the epoch is
reconstructed per row. The old const i32 offset let LLVM fold it. Worth re-trying once the epoch becomes const
upstream.
- covariance.rs::{update_batch,retract_batch} → and(is_not_null, is_not_null) + filter. Regressed sparse-null
shapes by +18% to +33% because filter allocates two new Float64Arrays per batch. Only +12% win on the no-null
path, not enough to justify a per-batch heuristic.
--
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: [I] Replace small hand-rolled element loops with arrow kernels and arity helpers [datafusion-comet]
Posted by "0lai0 (via GitHub)" <gi...@apache.org>.
0lai0 commented on issue #5091:
URL: https://github.com/apache/datafusion-comet/issues/5091#issuecomment-5325720667
Follow-up on the covariance item: the filter regression is real, but the readability problem this issue originally flagged is independent of which kernel you reach for. The dual flatten() iterators advanced conditionally on is_valid(i) can be replaced with
```
values1.iter().zip(values2.iter()).for_each(|pair| {
if let (Some(a), Some(b)) = pair {
// existing update logic
}
});
```
No extra allocation, same traversal count as today, and the null-sync becomes a single pattern match instead of two independent iterators. Worth trying before this item gets written off.
--
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