Skip to content

Commit

Permalink
Remove null array usage from list view (#1728)
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph-isaacs authored Dec 20, 2024
1 parent 1777c2f commit 9f3d8e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
13 changes: 2 additions & 11 deletions vortex-array/src/array/list/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ use serde::{Deserialize, Serialize};
use vortex_dtype::{match_each_native_ptype, DType, PType};
use vortex_error::{vortex_bail, vortex_panic, VortexExpect, VortexResult};

use crate::array::{NullArray, PrimitiveArray};
use crate::array::PrimitiveArray;
use crate::compute::{scalar_at, slice};
use crate::encoding::ids;
use crate::stats::{Stat, StatisticsVTable, StatsSet};
use crate::validity::{LogicalValidity, Validity, ValidityMetadata, ValidityVTable};
use crate::variants::{ListArrayTrait, PrimitiveArrayTrait, VariantsVTable};
use crate::visitor::{ArrayVisitor, VisitorVTable};
use crate::{
impl_encoding, ArrayDType, ArrayData, ArrayLen, ArrayTrait, Canonical, IntoArrayData,
IntoCanonical,
};
use crate::{impl_encoding, ArrayDType, ArrayData, ArrayLen, ArrayTrait, Canonical, IntoCanonical};

impl_encoding!("vortex.list", ids::LIST, List);

Expand Down Expand Up @@ -122,12 +119,6 @@ impl ListArray {

// TODO: fetches the elements at index
pub fn elements_at(&self, index: usize) -> VortexResult<ArrayData> {
if index >= self.len() {
vortex_bail!("Index out of bounds: index={} len={}", index, self.len());
}
if !self.is_valid(index) {
return Ok(NullArray::new(1).into_array());
}
let start = self.offset_at(index);
let end = self.offset_at(index + 1);
slice(self.elements(), start, end)
Expand Down
3 changes: 1 addition & 2 deletions vortex-array/src/builders/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,7 @@ mod tests {
let list_array = list.into_list().unwrap();

assert_eq!(list_array.elements_at(0).unwrap().len(), 3);
assert!(list_array.elements_at(1).unwrap().as_null_array().is_some());
assert_eq!(list_array.elements_at(1).unwrap().len(), 1);
assert_eq!(list_array.elements_at(1).unwrap().len(), 0);
assert_eq!(list_array.elements_at(2).unwrap().len(), 3);
}
}

0 comments on commit 9f3d8e1

Please sign in to comment.