17
17
18
18
//! Interleave elements from multiple arrays
19
19
20
- use crate :: dictionary:: { merge_dictionary_values, should_merge_dictionary_values} ;
20
+ use crate :: dictionary:: {
21
+ merge_dictionary_values, should_merge_dictionary_values, ShouldMergeValues ,
22
+ } ;
21
23
use arrow_array:: builder:: {
22
24
BooleanBufferBuilder , BufferBuilder , PrimitiveBuilder , PrimitiveDictionaryBuilder ,
23
25
} ;
@@ -198,9 +200,13 @@ fn interleave_dictionaries<K: ArrowDictionaryKeyType>(
198
200
indices : & [ ( usize , usize ) ] ,
199
201
) -> Result < ArrayRef , ArrowError > {
200
202
let dictionaries: Vec < _ > = arrays. iter ( ) . map ( |x| x. as_dictionary :: < K > ( ) ) . collect ( ) ;
201
- if !should_merge_dictionary_values :: < K > ( & dictionaries, indices. len ( ) ) {
202
- return interleave_fallback ( arrays, indices) ;
203
- }
203
+ let is_overflow = match should_merge_dictionary_values :: < K > ( & dictionaries, indices. len ( ) ) {
204
+ ShouldMergeValues :: ConcatWillOverflow => true ,
205
+ ShouldMergeValues :: Yes => false ,
206
+ ShouldMergeValues :: No => {
207
+ return interleave_fallback ( arrays, indices) ;
208
+ }
209
+ } ;
204
210
205
211
macro_rules! primitive_dict_helper {
206
212
( $t: ty) => {
@@ -213,8 +219,12 @@ fn interleave_dictionaries<K: ArrowDictionaryKeyType>(
213
219
DataType :: Utf8 | DataType :: LargeUtf8 | DataType :: Binary | DataType :: LargeBinary => {
214
220
merge_interleave_byte_dictionaries( & dictionaries, indices)
215
221
} ,
222
+ // merge not yet implemented for this type and it's not going to overflow, so fall back
223
+ // to concatenating values
224
+ _ if !is_overflow => interleave_fallback( arrays, indices) ,
216
225
other => Err ( ArrowError :: NotYetImplemented ( format!(
217
- "interleave does not yet support merging dictionaries with value type {other:?}"
226
+ "interleave of dictionaries would overflow key type {key_type:?} with value type {other:?}" ,
227
+ key_type = K :: DATA_TYPE ,
218
228
) ) )
219
229
}
220
230
}
0 commit comments