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

Commit

Permalink
Minor cleanup of internals. (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecarleitao authored Sep 26, 2021
1 parent 194a95d commit 05f41ae
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/array/fixed_size_binary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ impl FixedSizeBinaryArray {

assert_eq!(values.len() % size, 0);

if let Some(ref validity) = validity {
assert_eq!(values.len() / size, validity.len());
}

Self {
size,
data_type,
Expand Down Expand Up @@ -132,9 +136,8 @@ impl FixedSizeBinaryArray {

impl FixedSizeBinaryArray {
pub(crate) fn get_size(data_type: &DataType) -> &i32 {
match data_type {
match data_type.to_logical_type() {
DataType::FixedSizeBinary(size) => size,
DataType::Extension(_, child, _) => Self::get_size(child),
_ => panic!("Wrong DataType"),
}
}
Expand Down
23 changes: 13 additions & 10 deletions src/array/fixed_size_list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub use mutable::*;
/// Cloning and slicing this struct is `O(1)`.
#[derive(Debug, Clone)]
pub struct FixedSizeListArray {
size: i32, // this is redundant with `data_type`, but useful to not have to deconstruct the data_type.
size: usize, // this is redundant with `data_type`, but useful to not have to deconstruct the data_type.
data_type: DataType,
values: Arc<dyn Array>,
validity: Option<Bitmap>,
Expand Down Expand Up @@ -49,10 +49,14 @@ impl FixedSizeListArray {
) -> Self {
let (_, size) = Self::get_child_and_size(&data_type);

assert_eq!(values.len() % (*size as usize), 0);
assert_eq!(values.len() % size, 0);

if let Some(ref validity) = validity {
assert_eq!(values.len() / size, validity.len());
}

Self {
size: *size,
size,
data_type,
values,
validity,
Expand Down Expand Up @@ -118,7 +122,7 @@ impl FixedSizeListArray {
}

/// Returns the `Vec<T>` at position `i`.
/// # Safety:
/// # Safety
/// Caller must ensure that `i < self.len()`
#[inline]
pub unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array> {
Expand All @@ -140,15 +144,14 @@ impl FixedSizeListArray {
}

impl FixedSizeListArray {
pub(crate) fn get_child_and_size(data_type: &DataType) -> (&Field, &i32) {
match data_type {
DataType::FixedSizeList(child, size) => (child.as_ref(), size),
DataType::Extension(_, child, _) => Self::get_child_and_size(child),
_ => panic!("Wrong DataType"),
pub(crate) fn get_child_and_size(data_type: &DataType) -> (&Field, usize) {
match data_type.to_logical_type() {
DataType::FixedSizeList(child, size) => (child.as_ref(), *size as usize),
_ => panic!("FixedSizeListArray expects DataType::FixedSizeList"),
}
}

/// Returns a [`DataType`] consistent with this Array.
/// Returns a [`DataType`] consistent with [`FixedSizeListArray`].
pub fn default_datatype(data_type: DataType, size: usize) -> DataType {
let field = Box::new(Field::new("item", data_type, true));
DataType::FixedSizeList(field, size as i32)
Expand Down
14 changes: 8 additions & 6 deletions src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ impl<O: Offset> ListArray<O> {
) -> Self {
check_offsets(&offsets, values.len());

if let Some(ref validity) = validity {
assert_eq!(offsets.len() - 1, validity.len());
}

// validate data_type
let child_data_type = Self::get_child_type(&data_type);
assert_eq!(
Expand Down Expand Up @@ -172,16 +176,14 @@ impl<O: Offset> ListArray<O> {

pub fn get_child_field(data_type: &DataType) -> &Field {
if O::is_large() {
match data_type {
match data_type.to_logical_type() {
DataType::LargeList(child) => child.as_ref(),
DataType::Extension(_, child, _) => Self::get_child_field(child),
_ => panic!("Wrong DataType"),
_ => panic!("ListArray<i64> expects DataType::List or DataType::LargeList"),
}
} else {
match data_type {
match data_type.to_logical_type() {
DataType::List(child) => child.as_ref(),
DataType::Extension(_, child, _) => Self::get_child_field(child),
_ => panic!("Wrong DataType"),
_ => panic!("ListArray<i32> expects DataType::List or DataType::List"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ fn display_fmt<T: std::fmt::Display, I: IntoIterator<Item = Option<T>>>(

/// Trait that list arrays implement for the purposes of DRY.
pub trait IterableListArray: Array {
/// # Safety:
/// # Safety
/// The caller must ensure that `i < self.len()`
unsafe fn value_unchecked(&self, i: usize) -> Box<dyn Array>;
}
Expand Down

0 comments on commit 05f41ae

Please sign in to comment.