@@ -584,10 +584,10 @@ fn value_indices<T: PrimInt + Hash + Into<Scalar>>(
584
584
values : & [ T ] ,
585
585
validity : & Mask ,
586
586
) -> 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.
588
588
let mut buffer = BooleanBufferBuilder :: new ( values. len ( ) ) ;
589
589
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) ;
591
591
}
592
592
593
593
Mask :: from_buffer ( buffer. finish ( ) )
@@ -754,11 +754,13 @@ mod tests {
754
754
use vortex_array:: aliases:: hash_set:: HashSet ;
755
755
use vortex_array:: arrays:: PrimitiveArray ;
756
756
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 ;
759
761
760
- use crate :: Compressor ;
761
- use crate :: integer :: IntCompressor ;
762
+ use crate :: integer :: { IntCompressor , IntegerStats , SparseScheme } ;
763
+ use crate :: { Compressor , CompressorStats , Scheme } ;
762
764
763
765
#[ test]
764
766
fn test_empty ( ) {
@@ -824,4 +826,20 @@ mod tests {
824
826
let compressed = IntCompressor :: compress ( & array, false , 3 , & [ ] ) . unwrap ( ) ;
825
827
log:: info!( "WindowName compressed: {}" , compressed. tree_display( ) ) ;
826
828
}
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
+ }
827
845
}
0 commit comments