@@ -529,7 +529,7 @@ impl Codec {
529529 }
530530 DataType :: Union ( fields, mode) => {
531531 // similar to dictionaries and lists, we set descending to false and negate nulls_first
532- // since the encodedc ontents will be inverted if descending is set
532+ // since the encoded contents will be inverted if descending is set
533533 let options = SortOptions {
534534 descending : false ,
535535 nulls_first : sort_field. options . nulls_first != sort_field. options . descending ,
@@ -1739,14 +1739,20 @@ fn encode_column(
17391739 offsets : offsets_buf,
17401740 mode,
17411741 } => {
1742- let _union_array = column . as_any ( ) . downcast_ref :: < UnionArray > ( ) . unwrap ( ) ;
1743- let null_sentinel = if opts. descending { 0x00 } else { 0x01 } ;
1742+ let union_array = as_union_array ( column ) ;
1743+ let null_sentinel = null_sentinel ( opts) ;
17441744
17451745 offsets
17461746 . iter_mut ( )
17471747 . skip ( 1 )
17481748 . enumerate ( )
17491749 . for_each ( |( i, offset) | {
1750+ let sentinel = if union_array. is_valid ( i) {
1751+ 0x01
1752+ } else {
1753+ null_sentinel
1754+ } ;
1755+
17501756 let type_id = type_ids[ i] ;
17511757
17521758 let child_row_idx = match ( mode, offsets_buf) {
@@ -1760,7 +1766,7 @@ fn encode_column(
17601766 let child_row = child_rows[ type_id as usize ] . row ( child_row_idx) ;
17611767 let child_bytes = child_row. as_ref ( ) ;
17621768
1763- data[ * offset] = null_sentinel ;
1769+ data[ * offset] = sentinel ;
17641770
17651771 let type_id_byte = if opts. descending {
17661772 !( type_id as u8 )
0 commit comments