This is an automated email from the ASF dual-hosted git repository.
liurenjie1024 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-rust.git
The following commit(s) were added to refs/heads/main by this push:
new e5b59a7 Feature: Schema into_builder method (#381)
e5b59a7 is described below
commit e5b59a74e273cc3ee835cf070985cf75a96d41c0
Author: Christian <[email protected]>
AuthorDate: Tue May 28 06:18:05 2024 +0200
Feature: Schema into_builder method (#381)
---
crates/iceberg/src/spec/schema.rs | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/crates/iceberg/src/spec/schema.rs
b/crates/iceberg/src/spec/schema.rs
index 2dc9c4d..9364b3a 100644
--- a/crates/iceberg/src/spec/schema.rs
+++ b/crates/iceberg/src/spec/schema.rs
@@ -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)
@@ -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(