Skip to content

Commit 34315f0

Browse files
committed
I write bugs, I fix bugs
1 parent 85793c3 commit 34315f0

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

crates/iceberg/src/arrow/value.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,21 @@ impl ArrowArrayAccessor {
443443
arrow_schema: Some(schema_to_arrow_schema(table_schema)?),
444444
})
445445
}
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+
}
446461
}
447462

448463
impl PartnerAccessor<ArrayRef> for ArrowArrayAccessor {
@@ -468,21 +483,17 @@ impl PartnerAccessor<ArrayRef> for ArrowArrayAccessor {
468483
.ok_or_else(|| {
469484
Error::new(
470485
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+
),
472490
)
473491
})?;
474492

475493
let field_pos = struct_array
476494
.fields()
477495
.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))
486497
.ok_or_else(|| {
487498
Error::new(
488499
ErrorKind::DataInvalid,

0 commit comments

Comments
 (0)