Skip to content

Commit

Permalink
Feature: Schema into_builder method (apache#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
c-thiel authored May 28, 2024
1 parent 1bf80e1 commit e5b59a7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions crates/iceberg/src/spec/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,16 @@ impl Schema {
}
}

/// Create a new schema builder from a schema.
pub fn into_builder(self) -> SchemaBuilder {
SchemaBuilder {
schema_id: self.schema_id,
fields: self.r#struct.fields().to_vec(),
alias_to_id: self.alias_to_id,
identifier_field_ids: self.identifier_field_ids,
}
}

/// Get field by field id.
pub fn field_by_id(&self, field_id: i32) -> Option<&NestedFieldRef> {
self.id_to_field.get(&field_id)
Expand Down Expand Up @@ -1304,6 +1314,15 @@ table {
.contains("Invalid schema: multiple fields for name baz"));
}

#[test]
fn test_schema_into_builder() {
let original_schema = table_schema_nested();
let builder = original_schema.clone().into_builder();
let schema = builder.build().unwrap();

assert_eq!(original_schema, schema);
}

#[test]
fn test_schema_index_by_name() {
let expected_name_to_id = HashMap::from(
Expand Down

0 comments on commit e5b59a7

Please sign in to comment.