1- use arrow_buffer:: NullBuffer ;
21use num_traits:: PrimInt ;
32use vortex_dtype:: { DType , NativePType , match_each_integer_ptype} ;
43use vortex_error:: { VortexResult , vortex_err, vortex_panic} ;
@@ -24,6 +23,7 @@ impl TakeFn<&VarBinArray> for VarBinEncoding {
2423 data. as_slice( ) ,
2524 indices. as_slice:: <$I >( ) ,
2625 array. validity_mask( ) ?,
26+ indices. validity_mask( ) ?,
2727 ) ?. into_array( ) )
2828 } )
2929 } )
@@ -36,9 +36,17 @@ fn take<I: NativePType, O: NativePType + PrimInt>(
3636 data : & [ u8 ] ,
3737 indices : & [ I ] ,
3838 validity_mask : Mask ,
39+ indices_validity_mask : Mask ,
3940) -> VortexResult < VarBinArray > {
40- if let Some ( v) = validity_mask. to_null_buffer ( ) {
41- return Ok ( take_nullable ( dtype, offsets, data, indices, v) ) ;
41+ if !validity_mask. all_true ( ) || !indices_validity_mask. all_true ( ) {
42+ return Ok ( take_nullable (
43+ dtype,
44+ offsets,
45+ data,
46+ indices,
47+ validity_mask,
48+ indices_validity_mask,
49+ ) ) ;
4250 }
4351
4452 let mut builder = VarBinBuilder :: < O > :: with_capacity ( indices. len ( ) ) ;
@@ -62,19 +70,27 @@ fn take_nullable<I: NativePType, O: NativePType + PrimInt>(
6270 offsets : & [ O ] ,
6371 data : & [ u8 ] ,
6472 indices : & [ I ] ,
65- null_buffer : NullBuffer ,
73+ data_validity : Mask ,
74+ indices_validity : Mask ,
6675) -> VarBinArray {
6776 let mut builder = VarBinBuilder :: < O > :: with_capacity ( indices. len ( ) ) ;
68- for & idx in indices {
69- let idx = idx
77+ for ( idx, data_idx) in indices. iter ( ) . enumerate ( ) {
78+ if !indices_validity. value ( idx) {
79+ builder. append_null ( ) ;
80+ continue ;
81+ }
82+ let data_idx = data_idx
7083 . to_usize ( )
71- . unwrap_or_else ( || vortex_panic ! ( "Failed to convert index to usize: {}" , idx ) ) ;
72- if null_buffer . is_valid ( idx ) {
73- let start = offsets[ idx ] . to_usize ( ) . unwrap_or_else ( || {
74- vortex_panic ! ( "Failed to convert offset to usize: {}" , offsets[ idx ] )
84+ . unwrap_or_else ( || vortex_panic ! ( "Failed to convert index to usize: {}" , data_idx ) ) ;
85+ if data_validity . value ( data_idx ) {
86+ let start = offsets[ data_idx ] . to_usize ( ) . unwrap_or_else ( || {
87+ vortex_panic ! ( "Failed to convert offset to usize: {}" , offsets[ data_idx ] )
7588 } ) ;
76- let stop = offsets[ idx + 1 ] . to_usize ( ) . unwrap_or_else ( || {
77- vortex_panic ! ( "Failed to convert offset to usize: {}" , offsets[ idx + 1 ] )
89+ let stop = offsets[ data_idx + 1 ] . to_usize ( ) . unwrap_or_else ( || {
90+ vortex_panic ! (
91+ "Failed to convert offset to usize: {}" ,
92+ offsets[ data_idx + 1 ]
93+ )
7894 } ) ;
7995 builder. append_value ( & data[ start..stop] ) ;
8096 } else {
0 commit comments