@@ -162,6 +162,26 @@ where
162162 take ( cast_dict_values. as_ref ( ) , dict_array. keys ( ) , None )
163163}
164164
165+ /// Pack a data type into a dictionary array passing the values through a primitive array
166+ pub ( crate ) fn pack_array_to_dictionary_via_primitive < K : ArrowDictionaryKeyType > (
167+ array : & dyn Array ,
168+ primitive_type : DataType ,
169+ dict_value_type : & DataType ,
170+ cast_options : & CastOptions ,
171+ ) -> Result < ArrayRef , ArrowError > {
172+ let primitive = cast_with_options ( array, & primitive_type, cast_options) ?;
173+ let dict = cast_with_options (
174+ primitive. as_ref ( ) ,
175+ & DataType :: Dictionary ( Box :: new ( K :: DATA_TYPE ) , Box :: new ( primitive_type) ) ,
176+ cast_options,
177+ ) ?;
178+ cast_with_options (
179+ dict. as_ref ( ) ,
180+ & DataType :: Dictionary ( Box :: new ( K :: DATA_TYPE ) , Box :: new ( dict_value_type. clone ( ) ) ) ,
181+ cast_options,
182+ )
183+ }
184+
165185/// Attempts to encode an array into an `ArrayDictionary` with index
166186/// type K and value (dictionary) type value_type
167187///
@@ -188,6 +208,45 @@ pub(crate) fn cast_to_dictionary<K: ArrowDictionaryKeyType>(
188208 Decimal256 ( _, _) => {
189209 pack_numeric_to_dictionary :: < K , Decimal256Type > ( array, dict_value_type, cast_options)
190210 }
211+ Float16 => {
212+ pack_numeric_to_dictionary :: < K , Float16Type > ( array, dict_value_type, cast_options)
213+ }
214+ Float32 => {
215+ pack_numeric_to_dictionary :: < K , Float32Type > ( array, dict_value_type, cast_options)
216+ }
217+ Float64 => {
218+ pack_numeric_to_dictionary :: < K , Float64Type > ( array, dict_value_type, cast_options)
219+ }
220+ Date32 => pack_array_to_dictionary_via_primitive :: < K > (
221+ array,
222+ DataType :: Int32 ,
223+ dict_value_type,
224+ cast_options,
225+ ) ,
226+ Date64 => pack_array_to_dictionary_via_primitive :: < K > (
227+ array,
228+ DataType :: Int64 ,
229+ dict_value_type,
230+ cast_options,
231+ ) ,
232+ Time32 ( _) => pack_array_to_dictionary_via_primitive :: < K > (
233+ array,
234+ DataType :: Int32 ,
235+ dict_value_type,
236+ cast_options,
237+ ) ,
238+ Time64 ( _) => pack_array_to_dictionary_via_primitive :: < K > (
239+ array,
240+ DataType :: Int64 ,
241+ dict_value_type,
242+ cast_options,
243+ ) ,
244+ Timestamp ( _, _) => pack_array_to_dictionary_via_primitive :: < K > (
245+ array,
246+ DataType :: Int64 ,
247+ dict_value_type,
248+ cast_options,
249+ ) ,
191250 Utf8 => {
192251 // If the input is a view type, we can avoid casting (thus copying) the data
193252 if array. data_type ( ) == & DataType :: Utf8View {
0 commit comments