@@ -213,7 +213,7 @@ pub fn can_cast_types(from_type: &DataType, to_type: &DataType) -> bool {
213
213
214
214
( Binary , LargeBinary | Utf8 | LargeUtf8 | FixedSizeBinary ( _) | BinaryView | Utf8View ) => true ,
215
215
( LargeBinary , Binary | Utf8 | LargeUtf8 | FixedSizeBinary ( _) | BinaryView | Utf8View ) => true ,
216
- ( FixedSizeBinary ( _) , Binary | LargeBinary ) => true ,
216
+ ( FixedSizeBinary ( _) , Binary | LargeBinary | BinaryView ) => true ,
217
217
(
218
218
Utf8 | LargeUtf8 | Utf8View ,
219
219
Binary
@@ -1192,6 +1192,7 @@ pub fn cast_with_options(
1192
1192
( FixedSizeBinary ( size) , _) => match to_type {
1193
1193
Binary => cast_fixed_size_binary_to_binary :: < i32 > ( array, * size) ,
1194
1194
LargeBinary => cast_fixed_size_binary_to_binary :: < i64 > ( array, * size) ,
1195
+ BinaryView => cast_fixed_size_binary_to_binary_view ( array, * size) ,
1195
1196
_ => Err ( ArrowError :: CastError ( format ! (
1196
1197
"Casting from {from_type:?} to {to_type:?} not supported" ,
1197
1198
) ) ) ,
@@ -2327,6 +2328,27 @@ fn cast_fixed_size_binary_to_binary<O: OffsetSizeTrait>(
2327
2328
Ok ( Arc :: new ( builder. finish ( ) ) )
2328
2329
}
2329
2330
2331
+ fn cast_fixed_size_binary_to_binary_view (
2332
+ array : & dyn Array ,
2333
+ _byte_width : i32 ,
2334
+ ) -> Result < ArrayRef , ArrowError > {
2335
+ let array = array
2336
+ . as_any ( )
2337
+ . downcast_ref :: < FixedSizeBinaryArray > ( )
2338
+ . unwrap ( ) ;
2339
+
2340
+ let mut builder = BinaryViewBuilder :: with_capacity ( array. len ( ) ) ;
2341
+ for i in 0 ..array. len ( ) {
2342
+ if array. is_null ( i) {
2343
+ builder. append_null ( ) ;
2344
+ } else {
2345
+ builder. append_value ( array. value ( i) ) ;
2346
+ }
2347
+ }
2348
+
2349
+ Ok ( Arc :: new ( builder. finish ( ) ) )
2350
+ }
2351
+
2330
2352
/// Helper function to cast from one `ByteArrayType` to another and vice versa.
2331
2353
/// If the target one (e.g., `LargeUtf8`) is too large for the source array it will return an Error.
2332
2354
fn cast_byte_container < FROM , TO > ( array : & dyn Array ) -> Result < ArrayRef , ArrowError >
@@ -4847,6 +4869,12 @@ mod tests {
4847
4869
assert_eq ! ( bytes_1, down_cast. value( 0 ) ) ;
4848
4870
assert_eq ! ( bytes_2, down_cast. value( 1 ) ) ;
4849
4871
assert ! ( down_cast. is_null( 2 ) ) ;
4872
+
4873
+ let array_ref = cast ( & a1, & DataType :: BinaryView ) . unwrap ( ) ;
4874
+ let down_cast = array_ref. as_binary_view ( ) ;
4875
+ assert_eq ! ( bytes_1, down_cast. value( 0 ) ) ;
4876
+ assert_eq ! ( bytes_2, down_cast. value( 1 ) ) ;
4877
+ assert ! ( down_cast. is_null( 2 ) ) ;
4850
4878
}
4851
4879
4852
4880
#[ test]
0 commit comments