@@ -443,6 +443,21 @@ impl ArrowArrayAccessor {
443
443
arrow_schema : Some ( schema_to_arrow_schema ( table_schema) ?) ,
444
444
} )
445
445
}
446
+
447
+ /// Check if an arrow field matches the target field ID, either directly or through schema lookup
448
+ fn arrow_field_matches_id ( & self , arrow_field : & arrow_schema:: Field , target_id : i32 ) -> bool {
449
+ // First try direct match via field metadata
450
+ if let Ok ( id) = get_field_id ( arrow_field) {
451
+ id == target_id
452
+ } else {
453
+ // Only if direct match fails, try fallback via schema lookup
454
+ self . arrow_schema
455
+ . as_ref ( )
456
+ . and_then ( |schema| schema. field_with_name ( arrow_field. name ( ) ) . ok ( ) )
457
+ . and_then ( |field_from_schema| get_field_id ( field_from_schema) . ok ( ) )
458
+ . is_some_and ( |id| id == target_id)
459
+ }
460
+ }
446
461
}
447
462
448
463
impl PartnerAccessor < ArrayRef > for ArrowArrayAccessor {
@@ -468,21 +483,17 @@ impl PartnerAccessor<ArrayRef> for ArrowArrayAccessor {
468
483
. ok_or_else ( || {
469
484
Error :: new (
470
485
ErrorKind :: DataInvalid ,
471
- "The struct partner is not a struct array" ,
486
+ format ! (
487
+ "The struct partner is not a struct array, partner: {:?}" ,
488
+ struct_partner
489
+ ) ,
472
490
)
473
491
} ) ?;
474
492
475
493
let field_pos = struct_array
476
494
. fields ( )
477
495
. iter ( )
478
- . position ( |arrow_field| {
479
- get_field_id ( arrow_field) . is_ok_and ( |id| id == field. id )
480
- || self
481
- . arrow_schema
482
- . as_ref ( )
483
- . and_then ( |schema| schema. field_with_name ( & field. name ) . ok ( ) )
484
- . and_then ( |field_from_schema| get_field_id ( field_from_schema) . ok ( ) ) == Some ( field. id )
485
- } )
496
+ . position ( |arrow_field| self . arrow_field_matches_id ( arrow_field, field. id ) )
486
497
. ok_or_else ( || {
487
498
Error :: new (
488
499
ErrorKind :: DataInvalid ,
0 commit comments