Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Commit

Permalink
Changed &Option<Bitmap> to Option<&Bitmap>.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao committed Sep 20, 2021
1 parent 2e19615 commit 8e56e66
Show file tree
Hide file tree
Showing 63 changed files with 146 additions and 146 deletions.
2 changes: 1 addition & 1 deletion guide/src/high_level.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ Like `FromIterator`, this crate contains two sets of APIs to iterate over data.
an array `array: &PrimitiveArray<T>`, the following applies:

1. If you need to iterate over `Option<&T>`, use `array.iter()`
2. If you can operate over the values and validity independently, use `array.values() -> &Buffer<T>` and `array.validity() -> &Option<Bitmap>`
2. If you can operate over the values and validity independently, use `array.values() -> &Buffer<T>` and `array.validity() -> Option<&Bitmap>`

Note that case 1 is useful when e.g. you want to perform an operation that depends on both validity and values, while the latter is suitable for SIMD and copies, as they return contiguous memory regions (buffers and bitmaps). We will see below how to leverage these APIs.

Expand Down
4 changes: 2 additions & 2 deletions src/array/binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ impl<O: Offset> Array for BinaryArray<O> {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ impl<O: Offset> MutableArray for MutableBinaryArray<O> {
self.offsets.len() - 1
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ impl Array for BooleanArray {
}

#[inline]
fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

#[inline]
Expand Down
4 changes: 2 additions & 2 deletions src/array/boolean/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ impl MutableArray for MutableBooleanArray {
self.values.len()
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
2 changes: 1 addition & 1 deletion src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<K: DictionaryKey> Array for DictionaryArray<K> {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
fn validity(&self) -> Option<&Bitmap> {
self.keys.validity()
}

Expand Down
2 changes: 1 addition & 1 deletion src/array/dictionary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<K: DictionaryKey, M: 'static + MutableArray> MutableArray for MutableDictio
self.keys.len()
}

fn validity(&self) -> &Option<MutableBitmap> {
fn validity(&self) -> Option<&MutableBitmap> {
self.keys.validity()
}

Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ impl Array for FixedSizeBinaryArray {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_binary/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl MutableArray for MutableFixedSizeBinaryArray {
self.values.len() / self.size
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ impl Array for FixedSizeListArray {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/fixed_size_list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ impl<M: MutableArray + 'static> MutableArray for MutableFixedSizeListArray<M> {
self.values.len() / self.size
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
2 changes: 1 addition & 1 deletion src/array/growable/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use super::{make_growable, utils::extend_validity, Growable};
#[derive(Debug)]
pub struct GrowableDictionary<'a, K: DictionaryKey> {
keys_values: Vec<&'a [K]>,
keys_validities: Vec<&'a Option<Bitmap>>,
keys_validities: Vec<Option<&'a Bitmap>>,
key_values: MutableBuffer<K>,
key_validity: MutableBitmap,
use_validity: bool,
Expand Down
2 changes: 1 addition & 1 deletion src/array/growable/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::{utils::extend_validity, Growable};
pub struct GrowablePrimitive<'a, T: NativeType> {
data_type: DataType,
arrays: Vec<&'a [T]>,
validities: Vec<&'a Option<Bitmap>>,
validities: Vec<Option<&'a Bitmap>>,
use_validity: bool,
validity: MutableBitmap,
values: MutableBuffer<T>,
Expand Down
2 changes: 1 addition & 1 deletion src/array/growable/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub(super) fn build_extend_null_bits(array: &dyn Array, use_validity: bool) -> E
#[inline]
pub(super) fn extend_validity(
mutable_validity: &mut MutableBitmap,
validity: &Option<Bitmap>,
validity: Option<&Bitmap>,
start: usize,
len: usize,
use_validity: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,8 @@ impl<O: Offset> Array for ListArray<O> {
}

#[inline]
fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/list/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ impl<O: Offset, M: MutableArray + 'static> MutableArray for MutableListArray<O,
self.offsets.len() - 1
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait Array: std::fmt::Debug + Send + Sync {
/// The validity of the [`Array`]: every array has an optional [`Bitmap`] that, when available
/// specifies whether the array slot is valid or not (null).
/// When the validity is [`None`], all slots are valid.
fn validity(&self) -> &Option<Bitmap>;
fn validity(&self) -> Option<&Bitmap>;

/// The number of null slots on this [`Array`]. This is usually used to branch
/// implementations to cases where optimizations can be made.
Expand Down Expand Up @@ -112,7 +112,7 @@ pub trait MutableArray: std::fmt::Debug {
}

/// The optional validity of the array.
fn validity(&self) -> &Option<MutableBitmap>;
fn validity(&self) -> Option<&MutableBitmap>;

/// Convert itself to an (immutable) [`Array`].
fn as_arc(&mut self) -> Arc<dyn Array>;
Expand Down
4 changes: 2 additions & 2 deletions src/array/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl Array for NullArray {
&DataType::Null
}

fn validity(&self) -> &Option<Bitmap> {
&None
fn validity(&self) -> Option<&Bitmap> {
None
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ impl<T: NativeType> Array for PrimitiveArray<T> {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/primitive/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ impl<T: NativeType> MutableArray for MutablePrimitiveArray<T> {
self.values.len()
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ impl Array for StructArray {
}

#[inline]
fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/union/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl Array for UnionArray {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&None
fn validity(&self) -> Option<&Bitmap> {
None
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
4 changes: 2 additions & 2 deletions src/array/utf8/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ impl<O: Offset> Array for Utf8Array<O> {
&self.data_type
}

fn validity(&self) -> &Option<Bitmap> {
&self.validity
fn validity(&self) -> Option<&Bitmap> {
self.validity.as_ref()
}

fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Expand Down
6 changes: 3 additions & 3 deletions src/array/utf8/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ impl<O: Offset> MutableArray for MutableUtf8Array<O> {
self.offsets.len() - 1
}

fn validity(&self) -> &Option<MutableBitmap> {
&self.validity
fn validity(&self) -> Option<&MutableBitmap> {
self.validity.as_ref()
}

fn as_arc(&mut self) -> Arc<dyn Array> {
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<O: Offset> MutableUtf8Array<O> {
}

/// Extends [`MutableUtf8Array`] from an iterator of trusted len.
/// #Safety
/// # Safety
/// The iterator must be trusted len.
#[inline]
pub unsafe fn extend_trusted_len_unchecked<I, P>(&mut self, iterator: I)
Expand Down
2 changes: 1 addition & 1 deletion src/compute/aggregate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::array::*;
use crate::bitmap::Bitmap;
use crate::datatypes::PhysicalType;

fn validity_size(validity: &Option<Bitmap>) -> usize {
fn validity_size(validity: Option<&Bitmap>) -> usize {
validity.as_ref().map(|b| b.as_slice().0.len()).unwrap_or(0)
}

Expand Down
10 changes: 5 additions & 5 deletions src/compute/arity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ where
let values = array.values().iter().map(|v| op(*v));
let values = Buffer::from_trusted_len_iter(values);

PrimitiveArray::<O>::from_data(data_type, values, array.validity().clone())
PrimitiveArray::<O>::from_data(data_type, values, array.validity().cloned())
}

/// Version of unary that checks for errors in the closure used to create the
Expand All @@ -50,7 +50,7 @@ where
Ok(PrimitiveArray::<O>::from_data(
data_type,
values,
array.validity().clone(),
array.validity().cloned(),
))
}

Expand All @@ -77,7 +77,7 @@ where
let values = Buffer::from_trusted_len_iter(values);

(
PrimitiveArray::<O>::from_data(data_type, values, array.validity().clone()),
PrimitiveArray::<O>::from_data(data_type, values, array.validity().cloned()),
mut_bitmap.into(),
)
}
Expand Down Expand Up @@ -115,7 +115,7 @@ where
// the iteration, then the validity is changed to None to mark the value
// as Null
let bitmap: Bitmap = mut_bitmap.into();
let validity = combine_validities(array.validity(), &Some(bitmap));
let validity = combine_validities(array.validity(), Some(&bitmap));

PrimitiveArray::<O>::from_data(data_type, values, validity)
}
Expand Down Expand Up @@ -278,7 +278,7 @@ where
// creation of the values with the iterator. If an error was found during
// the iteration, then the validity is changed to None to mark the value
// as Null
let validity = combine_validities(&validity, &Some(bitmap));
let validity = combine_validities(validity.as_ref(), Some(&bitmap));

Ok(PrimitiveArray::<T>::from_data(data_type, values, validity))
}
2 changes: 1 addition & 1 deletion src/compute/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ pub fn or(lhs: &BooleanArray, rhs: &BooleanArray) -> Result<BooleanArray> {
/// ```
pub fn not(array: &BooleanArray) -> BooleanArray {
let values = !array.values();
let validity = array.validity().clone();
let validity = array.validity().cloned();
BooleanArray::from_data(DataType::Boolean, values, validity)
}

Expand Down
4 changes: 2 additions & 2 deletions src/compute/cast/binary_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub fn binary_to_large_binary(from: &BinaryArray<i32>, to_data_type: DataType) -
let values = from.values().clone();
let offsets = from.offsets().iter().map(|x| *x as i64);
let offsets = Buffer::from_trusted_len_iter(offsets);
BinaryArray::<i64>::from_data(to_data_type, offsets, values, from.validity().clone())
BinaryArray::<i64>::from_data(to_data_type, offsets, values, from.validity().cloned())
}

pub fn binary_large_to_binary(
Expand All @@ -24,7 +24,7 @@ pub fn binary_large_to_binary(
to_data_type,
offsets,
values,
from.validity().clone(),
from.validity().cloned(),
))
}

Expand Down
2 changes: 1 addition & 1 deletion src/compute/cast/boolean_to.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ where
.map(|x| if x { T::one() } else { T::default() });
let values = Buffer::<T>::from_trusted_len_iter(iter);

PrimitiveArray::<T>::from_data(T::DATA_TYPE, values, from.validity().clone())
PrimitiveArray::<T>::from_data(T::DATA_TYPE, values, from.validity().cloned())
}

/// Casts the [`BooleanArray`] to a [`Utf8Array`], casting trues to `"1"` and falses to `"0"`
Expand Down
6 changes: 3 additions & 3 deletions src/compute/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ fn cast_list<O: Offset>(
to_type.clone(),
array.offsets().clone(),
new_values,
array.validity().clone(),
array.validity().cloned(),
))
}

Expand All @@ -307,7 +307,7 @@ fn cast_list_to_large_list(array: &ListArray<i32>, to_type: &DataType) -> ListAr
to_type.clone(),
offets,
array.values().clone(),
array.validity().clone(),
array.validity().cloned(),
)
}

Expand All @@ -320,7 +320,7 @@ fn cast_large_to_list(array: &ListArray<i64>, to_type: &DataType) -> ListArray<i
to_type.clone(),
offets,
array.values().clone(),
array.validity().clone(),
array.validity().cloned(),
)
}

Expand Down
Loading

0 comments on commit 8e56e66

Please sign in to comment.