Skip to content

Commit 27a36b4

Browse files
committed
[arrow-array]: add PrimitiveArray mut-or-clone helpers
1 parent 304c8f5 commit 27a36b4

File tree

2 files changed

+536
-26
lines changed

2 files changed

+536
-26
lines changed

arrow-arith/src/arity.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,7 @@ where
121121
if a.is_empty() {
122122
return Ok(PrimitiveArray::from(ArrayData::new_empty(&O::DATA_TYPE)));
123123
}
124-
125-
let nulls = NullBuffer::union(a.logical_nulls().as_ref(), b.logical_nulls().as_ref());
126-
127-
let values = a
128-
.values()
129-
.into_iter()
130-
.zip(b.values())
131-
.map(|(l, r)| op(*l, *r));
132-
133-
let buffer: Vec<_> = values.collect();
134-
Ok(PrimitiveArray::new(buffer.into(), nulls))
124+
Ok(a.binary(b, op))
135125
}
136126

137127
/// Applies a binary and infallible function to values in two arrays, replacing
@@ -268,11 +258,10 @@ where
268258
if a.is_empty() {
269259
return Ok(PrimitiveArray::from(ArrayData::new_empty(&O::DATA_TYPE)));
270260
}
271-
let len = a.len();
272-
273261
if a.null_count() == 0 && b.null_count() == 0 {
274-
try_binary_no_nulls(len, a, b, op)
262+
try_binary_no_nulls(a.len(), a, b, op)
275263
} else {
264+
let len = a.len();
276265
let nulls =
277266
NullBuffer::union(a.logical_nulls().as_ref(), b.logical_nulls().as_ref()).unwrap();
278267

0 commit comments

Comments
 (0)