@@ -762,6 +762,20 @@ mod tests {
762762 array:: { DictionaryArray , Int32Array , NullArray , StringArray } ,
763763 datatypes:: Int32Type ,
764764 } ;
765+ /// Helper function to create a dictionary array with non-null keys but some null values
766+ /// Returns a dictionary array where:
767+ /// - keys are [0, 1, 2, 0, 1] (all non-null)
768+ /// - values are ["a", null, "c"]
769+ /// - so the keys reference: "a", null, "c", "a", null
770+ fn create_dictionary_with_null_values ( ) -> Result < DictionaryArray < Int32Type > > {
771+ let values = StringArray :: from ( vec ! [ Some ( "a" ) , None , Some ( "c" ) ] ) ;
772+ let keys = Int32Array :: from ( vec ! [ 0 , 1 , 2 , 0 , 1 ] ) ; // references "a", null, "c", "a", null
773+ Ok ( DictionaryArray :: < Int32Type > :: try_new (
774+ keys,
775+ Arc :: new ( values) ,
776+ ) ?)
777+ }
778+
765779 #[ test]
766780 fn count_accumulator_nulls ( ) -> Result < ( ) > {
767781 let mut accumulator = CountAccumulator :: new ( ) ;
@@ -772,12 +786,7 @@ mod tests {
772786
773787 #[ test]
774788 fn count_distinct_accumulator_dictionary_with_null_values ( ) -> Result < ( ) > {
775- // Create a dictionary array where:
776- // - keys aren't null
777- // - but values referenced by some keys are null
778- let values = StringArray :: from ( vec ! [ Some ( "a" ) , None , Some ( "c" ) ] ) ;
779- let keys = Int32Array :: from ( vec ! [ 0 , 1 , 2 , 0 , 1 ] ) ; // references "a", null, "c", "a", null
780- let dict_array = DictionaryArray :: < Int32Type > :: try_new ( keys, Arc :: new ( values) ) ?;
789+ let dict_array = create_dictionary_with_null_values ( ) ?;
781790
782791 // The expected behavior is that count_distinct should count only non-null values
783792 // which in this case are "a" and "c" (appearing as 0 and 2 in keys)
@@ -795,12 +804,7 @@ mod tests {
795804
796805 #[ test]
797806 fn count_accumulator_dictionary_with_null_values ( ) -> Result < ( ) > {
798- // Create a dictionary array where:
799- // - keys aren't null
800- // - but values referenced by some keys are null
801- let values = StringArray :: from ( vec ! [ Some ( "a" ) , None , Some ( "c" ) ] ) ;
802- let keys = Int32Array :: from ( vec ! [ 0 , 1 , 2 , 0 , 1 ] ) ; // references "a", null, "c", "a", null
803- let dict_array = DictionaryArray :: < Int32Type > :: try_new ( keys, Arc :: new ( values) ) ?;
807+ let dict_array = create_dictionary_with_null_values ( ) ?;
804808
805809 // The expected behavior is that count should only count non-null values
806810 let mut accumulator = CountAccumulator :: new ( ) ;
0 commit comments