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

Commit

Permalink
process comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ritchie46 committed Sep 13, 2021
1 parent bd43941 commit 99a80b7
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 114 deletions.
30 changes: 15 additions & 15 deletions src/array/binary/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::DataType,
error::{ArrowError, Result},
};
use crate::{bitmap::Bitmap, buffer::Buffer, datatypes::DataType};

use super::{
display_fmt, display_helper, specification::check_offsets, specification::Offset, Array,
Expand Down Expand Up @@ -99,6 +94,18 @@ impl<O: Offset> BinaryArray<O> {
offset: self.offset + offset,
}
}

/// Sets the validity bitmap on this [`BinaryArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}
}

// accessors
Expand Down Expand Up @@ -164,15 +171,8 @@ impl<O: Offset> Array for BinaryArray<O> {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/array/boolean/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::{
bitmap::Bitmap,
datatypes::{DataType, PhysicalType},
error::{ArrowError, Result},
};

use super::{display_fmt, Array};
Expand Down Expand Up @@ -92,6 +91,18 @@ impl BooleanArray {
pub fn values(&self) -> &Bitmap {
&self.values
}

/// Sets the validity bitmap on this [`BooleanArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}
}

impl Array for BooleanArray {
Expand Down Expand Up @@ -119,15 +130,8 @@ impl Array for BooleanArray {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
17 changes: 14 additions & 3 deletions src/array/dictionary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::sync::Arc;
use crate::{
bitmap::Bitmap,
datatypes::DataType,
error::Result,
scalar::{new_scalar, Scalar},
types::{NativeType, NaturalDataType},
};
Expand Down Expand Up @@ -84,6 +83,18 @@ impl<K: DictionaryKey> DictionaryArray<K> {
}
}

/// Sets the validity bitmap on this [`Array`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.values = Arc::from(arr.values.with_validity(validity));
arr
}

/// Returns the keys of the [`DictionaryArray`]. These keys can be used to fetch values
/// from `values`.
#[inline]
Expand Down Expand Up @@ -138,8 +149,8 @@ impl<K: DictionaryKey> Array for DictionaryArray<K> {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
self.values.with_validity(validity)
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
30 changes: 15 additions & 15 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::DataType,
error::{ArrowError, Result},
};
use crate::{bitmap::Bitmap, buffer::Buffer, datatypes::DataType, error::Result};

use super::{display_fmt, display_helper, ffi::ToFfi, Array};

Expand Down Expand Up @@ -98,6 +93,18 @@ impl FixedSizeBinaryArray {
pub fn size(&self) -> usize {
self.size as usize
}

/// Sets the validity bitmap on this [`FixedSizeBinaryArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}
}

impl FixedSizeBinaryArray {
Expand Down Expand Up @@ -133,15 +140,8 @@ impl Array for FixedSizeBinaryArray {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use std::sync::Arc;
use crate::{
bitmap::Bitmap,
datatypes::{DataType, Field},
error::{ArrowError, Result},
};

use super::{display_fmt, ffi::ToFfi, new_empty_array, new_null_array, Array};
Expand Down Expand Up @@ -91,6 +90,18 @@ impl FixedSizeListArray {
self.values
.slice(i * self.size as usize, self.size as usize)
}

/// Sets the validity bitmap on this [`FixedSizeListArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}
}

impl FixedSizeListArray {
Expand Down Expand Up @@ -132,15 +143,8 @@ impl Array for FixedSizeListArray {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
24 changes: 14 additions & 10 deletions src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::{DataType, Field},
error::{ArrowError, Result},
};

use super::{
Expand Down Expand Up @@ -118,6 +117,18 @@ impl<O: Offset> ListArray<O> {
pub fn values(&self) -> &Arc<dyn Array> {
&self.values
}

/// Sets the validity bitmap on this [`ListArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}
}

impl<O: Offset> ListArray<O> {
Expand Down Expand Up @@ -175,15 +186,8 @@ impl<O: Offset> Array for ListArray<O> {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ pub trait Array: std::fmt::Debug + Send + Sync {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array>;

/// Sets the validity bitmap on this [`Array`].
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>>;
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array>;
}

/// A trait describing a mutable array; i.e. an array whose values can be changed.
Expand Down
12 changes: 3 additions & 9 deletions src/array/null.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use crate::{
bitmap::Bitmap,
datatypes::DataType,
error::{ArrowError, Result},
};
use crate::{bitmap::Bitmap, datatypes::DataType};

use super::{ffi::ToFfi, Array};

Expand Down Expand Up @@ -67,10 +63,8 @@ impl Array for NullArray {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, _: Option<Bitmap>) -> Result<Box<dyn Array>> {
Err(ArrowError::Other(
"cannot set validity of a null array".into(),
))
fn with_validity(&self, _: Option<Bitmap>) -> Box<dyn Array> {
panic!("cannot set validity of a null array")
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/array/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
bitmap::Bitmap,
buffer::Buffer,
datatypes::*,
error::{ArrowError, Result},
error::ArrowError,
types::{days_ms, months_days_ns, NativeType},
};

Expand Down Expand Up @@ -94,6 +94,18 @@ impl<T: NativeType> PrimitiveArray<T> {
}
}

/// Sets the validity bitmap on this [`PrimitiveArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}

/// The values [`Buffer`].
#[inline]
pub fn values(&self) -> &Buffer<T> {
Expand Down Expand Up @@ -162,15 +174,8 @@ impl<T: NativeType> Array for PrimitiveArray<T> {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
25 changes: 15 additions & 10 deletions src/array/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::Arc;
use crate::{
bitmap::Bitmap,
datatypes::{DataType, Field},
error::{ArrowError, Result},
error::Result,
ffi,
};

Expand Down Expand Up @@ -117,6 +117,18 @@ impl StructArray {
}
}

/// Sets the validity bitmap on this [`StructArray`].
/// # Panic
/// This function panics iff `validity.len() < self.len()`.
pub fn with_validity(&self, validity: Option<Bitmap>) -> Self {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
panic!("validity should be as least as large as the array")
}
let mut arr = self.clone();
arr.validity = validity;
arr
}

/// Returns the values of this [`StructArray`].
pub fn values(&self) -> &[Arc<dyn Array>] {
&self.values
Expand Down Expand Up @@ -163,15 +175,8 @@ impl Array for StructArray {
fn slice(&self, offset: usize, length: usize) -> Box<dyn Array> {
Box::new(self.slice(offset, length))
}
fn with_validity(&self, validity: Option<Bitmap>) -> Result<Box<dyn Array>> {
if matches!(&validity, Some(bitmap) if bitmap.len() < self.len()) {
return Err(ArrowError::InvalidArgumentError(
"validity should be as least as large as the array".into(),
));
}
let mut arr = self.clone();
arr.validity = validity;
Ok(Box::new(arr))
fn with_validity(&self, validity: Option<Bitmap>) -> Box<dyn Array> {
Box::new(self.with_validity(validity))
}
}

Expand Down
Loading

0 comments on commit 99a80b7

Please sign in to comment.