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 ab5497b1 refactor: simplify NestedField constructors  (#1136)
ab5497b1 is described below

commit ab5497b1a3f1632132e03908b5dd7d16b50e0fa3
Author: xxchan <[email protected]>
AuthorDate: Wed Apr 2 22:14:11 2025 +0800

    refactor: simplify NestedField constructors  (#1136)
    
    Signed-off-by: xxchan <[email protected]>## Which issue does this PR
    close?
    
    - Closes #.
    
    ## What changes are included in this PR?
    
    
    
    ## Are these changes tested?
    
    
    Signed-off-by: xxchan <[email protected]>
    Co-authored-by: Renjie Liu <[email protected]>
---
 crates/iceberg/src/spec/datatypes.rs | 32 ++++----------------------------
 1 file changed, 4 insertions(+), 28 deletions(-)

diff --git a/crates/iceberg/src/spec/datatypes.rs 
b/crates/iceberg/src/spec/datatypes.rs
index c806d16e..73d534d5 100644
--- a/crates/iceberg/src/spec/datatypes.rs
+++ b/crates/iceberg/src/spec/datatypes.rs
@@ -608,37 +608,17 @@ impl NestedField {
 
     /// Construct a required field.
     pub fn required(id: i32, name: impl ToString, field_type: Type) -> Self {
-        Self {
-            id,
-            name: name.to_string(),
-            required: true,
-            field_type: Box::new(field_type),
-            doc: None,
-            initial_default: None,
-            write_default: None,
-        }
+        Self::new(id, name, field_type, true)
     }
 
     /// Construct an optional field.
     pub fn optional(id: i32, name: impl ToString, field_type: Type) -> Self {
-        Self {
-            id,
-            name: name.to_string(),
-            required: false,
-            field_type: Box::new(field_type),
-            doc: None,
-            initial_default: None,
-            write_default: None,
-        }
+        Self::new(id, name, field_type, false)
     }
 
     /// Construct list type's element field.
     pub fn list_element(id: i32, field_type: Type, required: bool) -> Self {
-        if required {
-            Self::required(id, LIST_FIELD_NAME, field_type)
-        } else {
-            Self::optional(id, LIST_FIELD_NAME, field_type)
-        }
+        Self::new(id, LIST_FIELD_NAME, field_type, required)
     }
 
     /// Construct map type's key field.
@@ -648,11 +628,7 @@ impl NestedField {
 
     /// Construct map type's value field.
     pub fn map_value_element(id: i32, field_type: Type, required: bool) -> 
Self {
-        if required {
-            Self::required(id, MAP_VALUE_FIELD_NAME, field_type)
-        } else {
-            Self::optional(id, MAP_VALUE_FIELD_NAME, field_type)
-        }
+        Self::new(id, MAP_VALUE_FIELD_NAME, field_type, required)
     }
 
     /// Set the field's doc.

Reply via email to