You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datafusion.apache.org by gi...@apache.org on 2025/10/20 19:55:28 UTC
(datafusion) branch main updated: perf: improve `ScalarValue::to_array_of_size` for Boolean and some null values (#18180)
This is an automated email from the ASF dual-hosted git repository.
github-bot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 54fff6080f perf: improve `ScalarValue::to_array_of_size` for Boolean and some null values (#18180)
54fff6080f is described below
commit 54fff6080f95b9e9313f145ad75c5ca5a49e8a9e
Author: Raz Luvaton <16...@users.noreply.github.com>
AuthorDate: Mon Oct 20 22:55:02 2025 +0300
perf: improve `ScalarValue::to_array_of_size` for Boolean and some null values (#18180)
## Which issue does this PR close?
N/A
## Rationale for this change
make stuff faster
## What changes are included in this PR?
1. updated Boolean scalar to array to use existing functions for
creating `BooleanArray` with the same value n times
2. Update None `Binary`/`BinaryView`/`FixedSizeBinary`/`LargeBinary` to
use `new_null_array` instead of repeat
## Are these changes tested?
Existing tests
## Are there any user-facing changes?
Nope
---
datafusion/common/src/scalar/mod.rs | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs
index 60ff1f4b2e..a70a027a8f 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -70,7 +70,7 @@ use arrow::array::{
TimestampNanosecondArray, TimestampSecondArray, UInt16Array, UInt32Array,
UInt64Array, UInt8Array, UnionArray,
};
-use arrow::buffer::ScalarBuffer;
+use arrow::buffer::{BooleanBuffer, ScalarBuffer};
use arrow::compute::kernels::cast::{cast_with_options, CastOptions};
use arrow::compute::kernels::numeric::{
add, add_wrapping, div, mul, mul_wrapping, rem, sub, sub_wrapping,
@@ -2888,9 +2888,17 @@ impl ScalarValue {
ScalarValue::Decimal256(e, precision, scale) => Arc::new(
ScalarValue::build_decimal256_array(*e, *precision, *scale, size)?,
),
- ScalarValue::Boolean(e) => {
- Arc::new(BooleanArray::from(vec![*e; size])) as ArrayRef
- }
+ ScalarValue::Boolean(e) => match e {
+ None => new_null_array(&DataType::Boolean, size),
+ Some(true) => {
+ Arc::new(BooleanArray::new(BooleanBuffer::new_set(size), None))
+ as ArrayRef
+ }
+ Some(false) => {
+ Arc::new(BooleanArray::new(BooleanBuffer::new_unset(size), None))
+ as ArrayRef
+ }
+ },
ScalarValue::Float64(e) => {
build_array_from_option!(Float64, Float64Array, e, size)
}
@@ -2973,15 +2981,13 @@ impl ScalarValue {
Some(value) => Arc::new(
repeat_n(Some(value.as_slice()), size).collect::<BinaryArray>(),
),
- None => Arc::new(repeat_n(None::<&str>, size).collect::<BinaryArray>()),
+ None => new_null_array(&DataType::Binary, size),
},
ScalarValue::BinaryView(e) => match e {
Some(value) => Arc::new(
repeat_n(Some(value.as_slice()), size).collect::<BinaryViewArray>(),
),
- None => {
- Arc::new(repeat_n(None::<&str>, size).collect::<BinaryViewArray>())
- }
+ None => new_null_array(&DataType::BinaryView, size),
},
ScalarValue::FixedSizeBinary(s, e) => match e {
Some(value) => Arc::new(
@@ -2991,21 +2997,13 @@ impl ScalarValue {
)
.unwrap(),
),
- None => Arc::new(
- FixedSizeBinaryArray::try_from_sparse_iter_with_size(
- repeat_n(None::<&[u8]>, size),
- *s,
- )
- .unwrap(),
- ),
+ None => Arc::new(FixedSizeBinaryArray::new_null(*s, size)),
},
ScalarValue::LargeBinary(e) => match e {
Some(value) => Arc::new(
repeat_n(Some(value.as_slice()), size).collect::<LargeBinaryArray>(),
),
- None => {
- Arc::new(repeat_n(None::<&str>, size).collect::<LargeBinaryArray>())
- }
+ None => new_null_array(&DataType::LargeBinary, size),
},
ScalarValue::List(arr) => {
if size == 1 {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datafusion.apache.org
For additional commands, e-mail: commits-help@datafusion.apache.org