Skip to content

Commit 74b10c8

Browse files
authored
fix: SparseScheme handles null values that are not equal to top value (#2586)
1 parent eb3e236 commit 74b10c8

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

vortex-btrblocks/src/integer.rs

+24-6
Original file line numberDiff line numberDiff line change
@@ -584,10 +584,10 @@ fn value_indices<T: PrimInt + Hash + Into<Scalar>>(
584584
values: &[T],
585585
validity: &Mask,
586586
) -> Mask {
587-
// Find all non-null positions that are not identical to the top value.
587+
// Find all null and non-null positions that are not identical to the top value.
588588
let mut buffer = BooleanBufferBuilder::new(values.len());
589589
for (idx, &value) in values.iter().enumerate() {
590-
buffer.append(validity.value(idx) && top_value != value);
590+
buffer.append(!validity.value(idx) || top_value != value);
591591
}
592592

593593
Mask::from_buffer(buffer.finish())
@@ -754,11 +754,13 @@ mod tests {
754754
use vortex_array::aliases::hash_set::HashSet;
755755
use vortex_array::arrays::PrimitiveArray;
756756
use vortex_array::validity::Validity;
757-
use vortex_array::{IntoArray, ToCanonical};
758-
use vortex_buffer::{Buffer, BufferMut, buffer_mut};
757+
use vortex_array::vtable::EncodingVTable;
758+
use vortex_array::{Array, IntoArray, ToCanonical};
759+
use vortex_buffer::{Buffer, BufferMut, buffer, buffer_mut};
760+
use vortex_sparse::SparseEncoding;
759761

760-
use crate::Compressor;
761-
use crate::integer::IntCompressor;
762+
use crate::integer::{IntCompressor, IntegerStats, SparseScheme};
763+
use crate::{Compressor, CompressorStats, Scheme};
762764

763765
#[test]
764766
fn test_empty() {
@@ -824,4 +826,20 @@ mod tests {
824826
let compressed = IntCompressor::compress(&array, false, 3, &[]).unwrap();
825827
log::info!("WindowName compressed: {}", compressed.tree_display());
826828
}
829+
830+
#[test]
831+
fn sparse_with_nulls() {
832+
let array = PrimitiveArray::new(
833+
buffer![189u8, 189, 189, 0, 46],
834+
Validity::from_iter(vec![true, true, true, true, false]),
835+
);
836+
let compressed = SparseScheme
837+
.compress(&IntegerStats::generate(&array), false, 3, &[])
838+
.unwrap();
839+
assert_eq!(compressed.encoding(), SparseEncoding.id());
840+
let decoded = compressed.to_primitive().unwrap();
841+
let expected = [189u8, 189, 189, 0, 0];
842+
assert_eq!(decoded.as_slice::<u8>(), &expected);
843+
assert_eq!(decoded.validity(), array.validity());
844+
}
827845
}

0 commit comments

Comments
 (0)