Skip to content

Commit ab5497b

Browse files
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]>
1 parent f17dd4d commit ab5497b

File tree

1 file changed

+4
-28
lines changed

1 file changed

+4
-28
lines changed

crates/iceberg/src/spec/datatypes.rs

+4-28
Original file line numberDiff line numberDiff line change
@@ -608,37 +608,17 @@ impl NestedField {
608608

609609
/// Construct a required field.
610610
pub fn required(id: i32, name: impl ToString, field_type: Type) -> Self {
611-
Self {
612-
id,
613-
name: name.to_string(),
614-
required: true,
615-
field_type: Box::new(field_type),
616-
doc: None,
617-
initial_default: None,
618-
write_default: None,
619-
}
611+
Self::new(id, name, field_type, true)
620612
}
621613

622614
/// Construct an optional field.
623615
pub fn optional(id: i32, name: impl ToString, field_type: Type) -> Self {
624-
Self {
625-
id,
626-
name: name.to_string(),
627-
required: false,
628-
field_type: Box::new(field_type),
629-
doc: None,
630-
initial_default: None,
631-
write_default: None,
632-
}
616+
Self::new(id, name, field_type, false)
633617
}
634618

635619
/// Construct list type's element field.
636620
pub fn list_element(id: i32, field_type: Type, required: bool) -> Self {
637-
if required {
638-
Self::required(id, LIST_FIELD_NAME, field_type)
639-
} else {
640-
Self::optional(id, LIST_FIELD_NAME, field_type)
641-
}
621+
Self::new(id, LIST_FIELD_NAME, field_type, required)
642622
}
643623

644624
/// Construct map type's key field.
@@ -648,11 +628,7 @@ impl NestedField {
648628

649629
/// Construct map type's value field.
650630
pub fn map_value_element(id: i32, field_type: Type, required: bool) -> Self {
651-
if required {
652-
Self::required(id, MAP_VALUE_FIELD_NAME, field_type)
653-
} else {
654-
Self::optional(id, MAP_VALUE_FIELD_NAME, field_type)
655-
}
631+
Self::new(id, MAP_VALUE_FIELD_NAME, field_type, required)
656632
}
657633

658634
/// Set the field's doc.

0 commit comments

Comments
 (0)