Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Schema into_builder method #381

Merged
merged 3 commits into from
May 28, 2024
Merged
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
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
Loading