Skip to content

Commit

Permalink
Validity array (#185)
Browse files Browse the repository at this point in the history
Fixes #173
  • Loading branch information
gatesn authored Apr 3, 2024
1 parent 909eccc commit 1aed3c5
Show file tree
Hide file tree
Showing 69 changed files with 287 additions and 251 deletions.
12 changes: 5 additions & 7 deletions vortex-alp/src/array.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::sync::{Arc, RwLock};

use vortex::array::validity::Validity;
use vortex::array::{Array, ArrayKind, ArrayRef};
use vortex::compress::EncodingCompression;
use vortex::compute::ArrayCompute;
use vortex::encoding::{Encoding, EncodingId, EncodingRef};
use vortex::formatter::{ArrayDisplay, ArrayFormatter};
use vortex::serde::{ArraySerde, EncodingSerde};
use vortex::stats::{Stats, StatsSet};
use vortex::validity::{ArrayValidity, Validity};
use vortex::{impl_array, ArrayWalker};
use vortex_error::{vortex_bail, vortex_err, VortexResult};
use vortex_schema::{DType, IntWidth, Signedness};
Expand Down Expand Up @@ -114,6 +114,10 @@ impl Array for ALPArray {
self.encoded().nbytes() + self.patches().map(|p| p.nbytes()).unwrap_or(0)
}

fn validity(&self) -> Option<Validity> {
self.encoded().validity()
}

fn serde(&self) -> Option<&dyn ArraySerde> {
Some(self)
}
Expand All @@ -131,12 +135,6 @@ impl ArrayDisplay for ALPArray {
}
}

impl ArrayValidity for ALPArray {
fn validity(&self) -> Option<Validity> {
self.encoded().validity()
}
}

#[derive(Debug)]
pub struct ALPEncoding;

Expand Down
1 change: 0 additions & 1 deletion vortex-alp/src/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use vortex::compress::{CompressConfig, CompressCtx, EncodingCompression};
use vortex::compute::flatten::flatten_primitive;
use vortex::compute::patch::patch;
use vortex::ptype::{NativePType, PType};
use vortex::validity::ArrayValidity;
use vortex_error::{vortex_bail, vortex_err, VortexResult};

use crate::alp::ALPFloat;
Expand Down
6 changes: 3 additions & 3 deletions vortex-array/src/array/bool/compute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use vortex_error::VortexResult;

use crate::array::bool::BoolArray;
use crate::array::downcast::DowncastArrayBuiltin;
use crate::array::{Array, ArrayRef};
use crate::array::validity::Validity;
use crate::array::{Array, ArrayRef, ArrayValidity};
use crate::arrow::wrappers::as_nulls;
use crate::compute::as_arrow::AsArrowArray;
use crate::compute::as_contiguous::AsContiguousFn;
Expand All @@ -16,7 +17,6 @@ use crate::compute::scalar_at::ScalarAtFn;
use crate::compute::take::TakeFn;
use crate::compute::ArrayCompute;
use crate::scalar::{BoolScalar, Scalar};
use crate::validity::{ArrayValidity, Validity};

mod take;

Expand Down Expand Up @@ -122,8 +122,8 @@ impl FillForwardFn for BoolArray {
mod test {
use crate::array::bool::BoolArray;
use crate::array::downcast::DowncastArrayBuiltin;
use crate::array::Array;
use crate::compute;
use crate::validity::ArrayValidity;

#[test]
fn fill_forward() {
Expand Down
1 change: 0 additions & 1 deletion vortex-array/src/array/bool/compute/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use crate::array::{Array, ArrayRef};
use crate::compute::flatten::flatten_primitive;
use crate::compute::take::TakeFn;
use crate::match_each_integer_ptype;
use crate::validity::ArrayValidity;

impl TakeFn for BoolArray {
fn take(&self, indices: &dyn Array) -> VortexResult<ArrayRef> {
Expand Down
12 changes: 5 additions & 7 deletions vortex-array/src/array/bool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use vortex_error::VortexResult;
use vortex_schema::{DType, Nullability};

use super::{check_slice_bounds, Array, ArrayRef};
use crate::array::validity::Validity;
use crate::array::IntoArray;
use crate::compute::ArrayCompute;
use crate::encoding::{Encoding, EncodingId, EncodingRef, ENCODINGS};
use crate::formatter::{ArrayDisplay, ArrayFormatter};
use crate::serde::{ArraySerde, EncodingSerde};
use crate::stats::{Stat, Stats, StatsSet};
use crate::validity::{ArrayValidity, Validity};
use crate::{impl_array, ArrayWalker};

mod compute;
Expand Down Expand Up @@ -102,6 +102,10 @@ impl Array for BoolArray {
.into_array())
}

fn validity(&self) -> Option<Validity> {
self.validity.clone()
}

#[inline]
fn encoding(&self) -> EncodingRef {
&BoolEncoding
Expand All @@ -125,12 +129,6 @@ impl Array for BoolArray {
}
}

impl ArrayValidity for BoolArray {
fn validity(&self) -> Option<Validity> {
self.validity.clone()
}
}

#[derive(Debug)]
pub struct BoolEncoding;

Expand Down
3 changes: 1 addition & 2 deletions vortex-array/src/array/bool/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use vortex_error::VortexResult;
use crate::array::bool::{BoolArray, BoolEncoding};
use crate::array::{Array, ArrayRef};
use crate::serde::{ArraySerde, ArrayView, BytesSerde, EncodingSerde, ReadCtx, WriteCtx};
use crate::validity::ArrayValidity;

impl ArraySerde for BoolArray {
fn write(&self, ctx: &mut WriteCtx) -> VortexResult<()> {
Expand Down Expand Up @@ -33,8 +32,8 @@ impl EncodingSerde for BoolEncoding {
mod test {
use crate::array::bool::BoolArray;
use crate::array::downcast::DowncastArrayBuiltin;
use crate::array::Array;
use crate::serde::test::roundtrip_array;
use crate::validity::ArrayValidity;

#[test]
fn roundtrip() {
Expand Down
18 changes: 8 additions & 10 deletions vortex-array/src/array/chunked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ use linkme::distributed_slice;
use vortex_error::{vortex_bail, VortexResult};
use vortex_schema::DType;

use crate::array::validity::Validity;
use crate::array::{check_slice_bounds, Array, ArrayRef};
use crate::compute::ArrayCompute;
use crate::encoding::{Encoding, EncodingId, EncodingRef, ENCODINGS};
use crate::formatter::{ArrayDisplay, ArrayFormatter};
use crate::serde::{ArraySerde, EncodingSerde};
use crate::stats::{Stats, StatsSet};
use crate::validity::{ArrayValidity, Validity};
use crate::{impl_array, ArrayWalker};

mod compute;
Expand Down Expand Up @@ -145,15 +145,6 @@ impl Array for ChunkedArray {
Some(self)
}

fn walk(&self, walker: &mut dyn ArrayWalker) -> VortexResult<()> {
for chunk in self.chunks() {
walker.visit_child(&chunk)?;
}
Ok(())
}
}

impl ArrayValidity for ChunkedArray {
fn validity(&self) -> Option<Validity> {
if !self.dtype.is_nullable() {
return None;
Expand All @@ -165,6 +156,13 @@ impl ArrayValidity for ChunkedArray {
.unwrap_or_else(|| Validity::Valid(chunk.len()))
})))
}

fn walk(&self, walker: &mut dyn ArrayWalker) -> VortexResult<()> {
for chunk in self.chunks() {
walker.visit_child(&chunk)?;
}
Ok(())
}
}

impl FromIterator<ArrayRef> for ChunkedArray {
Expand Down
12 changes: 5 additions & 7 deletions vortex-array/src/array/composite/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use vortex_error::VortexResult;
use vortex_schema::{CompositeID, DType};

use crate::array::composite::{find_extension, CompositeExtensionRef, TypedCompositeArray};
use crate::array::validity::Validity;
use crate::array::{Array, ArrayRef};
use crate::compress::EncodingCompression;
use crate::compute::ArrayCompute;
use crate::encoding::{Encoding, EncodingId, EncodingRef, ENCODINGS};
use crate::formatter::{ArrayDisplay, ArrayFormatter};
use crate::serde::{ArraySerde, BytesSerde, EncodingSerde};
use crate::stats::{Stats, StatsCompute, StatsSet};
use crate::validity::{ArrayValidity, Validity};
use crate::{impl_array, ArrayWalker};

pub trait CompositeMetadata:
Expand Down Expand Up @@ -121,19 +121,17 @@ impl Array for CompositeArray {
Some(self)
}

fn validity(&self) -> Option<Validity> {
self.underlying().validity()
}

fn walk(&self, walker: &mut dyn ArrayWalker) -> VortexResult<()> {
walker.visit_child(self.underlying())
}
}

impl StatsCompute for CompositeArray {}

impl ArrayValidity for CompositeArray {
fn validity(&self) -> Option<Validity> {
self.underlying().validity()
}
}

impl ArrayDisplay for CompositeArray {
fn fmt(&self, f: &mut ArrayFormatter) -> std::fmt::Result {
f.property("metadata", format!("{:#?}", self.metadata().as_slice()))?;
Expand Down
4 changes: 2 additions & 2 deletions vortex-array/src/array/constant/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ use crate::array::bool::BoolArray;
use crate::array::constant::ConstantArray;
use crate::array::downcast::DowncastArrayBuiltin;
use crate::array::primitive::PrimitiveArray;
use crate::array::{Array, ArrayRef};
use crate::array::validity::Validity;
use crate::array::{Array, ArrayRef, ArrayValidity};
use crate::compute::as_contiguous::AsContiguousFn;
use crate::compute::flatten::{FlattenFn, FlattenedArray};
use crate::compute::scalar_at::ScalarAtFn;
use crate::compute::take::TakeFn;
use crate::compute::ArrayCompute;
use crate::match_each_native_ptype;
use crate::scalar::Scalar;
use crate::validity::{ArrayValidity, Validity};

impl ArrayCompute for ConstantArray {
fn as_contiguous(&self) -> Option<&dyn AsContiguousFn> {
Expand Down
12 changes: 5 additions & 7 deletions vortex-array/src/array/constant/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use linkme::distributed_slice;
use vortex_error::VortexResult;
use vortex_schema::DType;

use crate::array::validity::Validity;
use crate::array::{check_slice_bounds, Array, ArrayRef};
use crate::compute::ArrayCompute;
use crate::encoding::{Encoding, EncodingId, EncodingRef, ENCODINGS};
use crate::formatter::{ArrayDisplay, ArrayFormatter};
use crate::scalar::Scalar;
use crate::serde::{ArraySerde, EncodingSerde};
use crate::stats::{Stat, Stats, StatsSet};
use crate::validity::{ArrayValidity, Validity};
use crate::{impl_array, ArrayWalker};

mod compute;
Expand Down Expand Up @@ -96,12 +96,6 @@ impl Array for ConstantArray {
Some(self)
}

fn walk(&self, _walker: &mut dyn ArrayWalker) -> VortexResult<()> {
Ok(())
}
}

impl ArrayValidity for ConstantArray {
fn validity(&self) -> Option<Validity> {
match self.scalar.dtype().is_nullable() {
true => match self.scalar().is_null() {
Expand All @@ -111,6 +105,10 @@ impl ArrayValidity for ConstantArray {
false => None,
}
}

fn walk(&self, _walker: &mut dyn ArrayWalker) -> VortexResult<()> {
Ok(())
}
}

impl ArrayDisplay for ConstantArray {
Expand Down
Loading

0 comments on commit 1aed3c5

Please sign in to comment.