Skip to content

Commit e5b59a7

Browse files
authored
Feature: Schema into_builder method (#381)
1 parent 1bf80e1 commit e5b59a7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

crates/iceberg/src/spec/schema.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,16 @@ impl Schema {
269269
}
270270
}
271271

272+
/// Create a new schema builder from a schema.
273+
pub fn into_builder(self) -> SchemaBuilder {
274+
SchemaBuilder {
275+
schema_id: self.schema_id,
276+
fields: self.r#struct.fields().to_vec(),
277+
alias_to_id: self.alias_to_id,
278+
identifier_field_ids: self.identifier_field_ids,
279+
}
280+
}
281+
272282
/// Get field by field id.
273283
pub fn field_by_id(&self, field_id: i32) -> Option<&NestedFieldRef> {
274284
self.id_to_field.get(&field_id)
@@ -1304,6 +1314,15 @@ table {
13041314
.contains("Invalid schema: multiple fields for name baz"));
13051315
}
13061316

1317+
#[test]
1318+
fn test_schema_into_builder() {
1319+
let original_schema = table_schema_nested();
1320+
let builder = original_schema.clone().into_builder();
1321+
let schema = builder.build().unwrap();
1322+
1323+
assert_eq!(original_schema, schema);
1324+
}
1325+
13071326
#[test]
13081327
fn test_schema_index_by_name() {
13091328
let expected_name_to_id = HashMap::from(

0 commit comments

Comments
 (0)