Skip to content

Commit 2682884

Browse files
committed
Add into_parts-type functions for consuming PrimitiveArray and BooleanArray
1 parent 288795e commit 2682884

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

arrow/src/array/array_boolean.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::{any::Any, fmt};
2222

2323
use super::*;
2424
use super::{array::print_long_array, raw_pointer::RawPtrBox};
25+
use crate::bitmap::Bitmap;
2526
use crate::buffer::{Buffer, MutableBuffer};
2627
use crate::util::bit_util;
2728

@@ -109,6 +110,12 @@ impl BooleanArray {
109110
debug_assert!(i < self.len());
110111
unsafe { self.value_unchecked(i) }
111112
}
113+
114+
/// Returns (_, _, offset, length)
115+
pub fn into_parts(self) -> (Buffer, Option<Bitmap>, usize, usize) {
116+
let data = self.data;
117+
data.into_1_dimensional_parts()
118+
}
112119
}
113120

114121
impl Array for BooleanArray {

arrow/src/array/array_primitive.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ impl<T: ArrowPrimitiveType> PrimitiveArray<T> {
146146
);
147147
PrimitiveArray::from(data)
148148
}
149+
150+
pub fn into_data(self) -> ArrayData {
151+
self.data
152+
}
149153
}
150154

151155
impl<T: ArrowPrimitiveType> Array for PrimitiveArray<T> {

arrow/src/array/data.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,15 @@ impl ArrayData {
478478

479479
Self::new(data_type.clone(), 0, Some(0), None, 0, buffers, child_data)
480480
}
481+
482+
pub fn into_1_dimensional_parts(self) -> (Buffer, Option<Bitmap>, usize, usize) {
483+
let offset: usize = self.offset;
484+
let length: usize = self.len;
485+
let buffers: Vec<Buffer> = self.buffers;
486+
let bitmap: Option<Bitmap> = self.null_bitmap;
487+
let buffer0: Buffer = buffers.into_iter().next().unwrap();
488+
(buffer0, bitmap, offset, length)
489+
}
481490
}
482491

483492
impl PartialEq for ArrayData {

0 commit comments

Comments
 (0)