Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SparseArray validity logic and give DateTimeParts unique code #495

Merged
merged 3 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion encodings/datetime-parts/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use vortex_error::{vortex_bail, VortexResult};

use crate::compute::decode_to_temporal;

impl_encoding!("vortex.datetimeparts", 20u16, DateTimeParts);
impl_encoding!("vortex.datetimeparts", 22u16, DateTimeParts);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh whoops, this actually collides with runendbools

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct DateTimePartsMetadata {
Expand Down
4 changes: 2 additions & 2 deletions vortex-array/src/array/sparse/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ fn canonicalize_sparse_bools(
fill_value.try_into()?
};
let mut flat_bools = vec![fill_bool; len];
for idx in indices {
flat_bools[*idx] = values.value(*idx);
for (i, idx) in indices.iter().enumerate() {
flat_bools[*idx] = values.value(i);
validity.set_bit(*idx, true);
}

Expand Down
29 changes: 25 additions & 4 deletions vortex-array/src/array/sparse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ impl SparseArray {
values.dtype(),
);
}
if indices.len() != values.len() {
vortex_bail!(
"Mismatched indices {} and values {} length",
indices.len(),
values.len()
);
}

Self::try_from_parts(
values.dtype().clone(),
Expand All @@ -80,7 +87,7 @@ impl SparseArray {
#[inline]
pub fn values(&self) -> Array {
self.array()
.child(1, self.dtype(), self.indices().len())
.child(1, self.dtype(), self.metadata().indices_len)
.expect("missing child array")
}

Expand Down Expand Up @@ -157,10 +164,10 @@ impl ArrayValidity for SparseArray {
// of true, and patch values of false.
Self::try_new_with_offset(
self.indices(),
ConstantArray::new(false, self.len()).into_array(),
ConstantArray::new(true, self.indices().len()).into_array(),
robert3005 marked this conversation as resolved.
Show resolved Hide resolved
self.len(),
self.indices_offset(),
true.into(),
false.into(),
)
} else {
// If the fill_value is non-null, then the validity is based on the validity of the
Expand All @@ -171,7 +178,7 @@ impl ArrayValidity for SparseArray {
.with_dyn(|a| a.logical_validity().into_array()),
self.len(),
self.indices_offset(),
true.into(),
false.into(),
)
}
.unwrap();
Expand Down Expand Up @@ -338,4 +345,18 @@ mod test {
assert_eq!(start, 0);
assert_eq!(stop, 5);
}

#[test]
pub fn sparse_logical_validity() {
let array = sparse_array(nullable_fill());
let validity = array
.with_dyn(|a| a.logical_validity())
.into_array()
.into_bool()
.unwrap();
assert_eq!(
validity.boolean_buffer().iter().collect_vec(),
[false, false, true, false, false, true, false, false, true, false]
);
}
}
Loading