Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/iceberg/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod statistic_file;
mod table_metadata;
mod table_metadata_builder;
mod transform;
pub(crate) mod update;
mod values;
mod view_metadata;
mod view_version;
Expand Down
22 changes: 22 additions & 0 deletions crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,28 @@ impl Schema {
pub(crate) fn field_id_to_name_map(&self) -> &HashMap<i32, String> {
&self.id_to_name
}

/// id to parent
pub fn id_to_parent(&self) -> HashMap<i32, String> {
let mut id_to_parent = HashMap::new();
let root_name = String::from("<root>");
Self::build_id_to_parent(self.as_struct(), &root_name, &mut id_to_parent);
id_to_parent
}

/// Helper function to recursively build the ID-to-parent mapping.
fn build_id_to_parent(
struct_type: &StructType,
parent_name: &str,
id_to_parent: &mut HashMap<i32, String>,
) {
for field in struct_type.fields() {
id_to_parent.insert(field.id, parent_name.to_string());
if let Type::Struct(ref nested_struct) = *field.field_type {
Self::build_id_to_parent(nested_struct, &field.name, id_to_parent);
}
}
}
}

impl Display for Schema {
Expand Down
Loading
Loading