This is an automated email from the ASF dual-hosted git repository.
blackmwk 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 db8f44e4e feat(datatypes): add optional and required constructors for
MapType (#2405)
db8f44e4e is described below
commit db8f44e4ec34e265c6276cd4672667af6bf195d6
Author: Liang Gong <[email protected]>
AuthorDate: Wed May 6 17:50:45 2026 +0800
feat(datatypes): add optional and required constructors for MapType (#2405)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
Just two simple APIs for construction of MapType. No issue related.
## What changes are included in this PR?
<!--
Provide a summary of the modifications in this PR. List the main changes
such as new features, bug fixes, refactoring, or any other updates.
-->
As you can see, all changes are made in
`crates/iceberg/src/datatypes.rs`.
## Are these changes tested?
<!--
Specify what test covers (unit test, integration test, etc.).
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
Yes. Moreover, I supplemented the test cases.
---
crates/iceberg/src/spec/datatypes.rs | 60 ++++++++++++++++++++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/crates/iceberg/src/spec/datatypes.rs
b/crates/iceberg/src/spec/datatypes.rs
index 037946558..ad4aea758 100644
--- a/crates/iceberg/src/spec/datatypes.rs
+++ b/crates/iceberg/src/spec/datatypes.rs
@@ -826,6 +826,22 @@ impl MapType {
value_field,
}
}
+
+ /// Construct an optional map type with the given key and value fields.
+ pub fn optional(key_id: i32, key_type: Type, value_id: i32, value_type:
Type) -> Self {
+ Self {
+ key_field: NestedField::map_key_element(key_id, key_type).into(),
+ value_field: NestedField::map_value_element(value_id, value_type,
false).into(),
+ }
+ }
+
+ /// Construct a required map type with the given key and value fields.
+ pub fn required(key_id: i32, key_type: Type, value_id: i32, value_type:
Type) -> Self {
+ Self {
+ key_field: NestedField::map_key_element(key_id, key_type).into(),
+ value_field: NestedField::map_value_element(value_id, value_type,
true).into(),
+ }
+ }
}
#[cfg(test)]
@@ -1135,6 +1151,16 @@ mod tests {
.into(),
}),
);
+
+ check_type_serde(
+ record,
+ Type::Map(MapType::optional(
+ 4,
+ Type::Primitive(PrimitiveType::String),
+ 5,
+ Type::Primitive(PrimitiveType::Double),
+ )),
+ );
}
#[test]
@@ -1163,6 +1189,40 @@ mod tests {
.into(),
}),
);
+
+ check_type_serde(
+ record,
+ Type::Map(MapType::optional(
+ 4,
+ Type::Primitive(PrimitiveType::Int),
+ 5,
+ Type::Primitive(PrimitiveType::String),
+ )),
+ );
+ }
+
+ #[test]
+ fn map_required_int() {
+ let record = r#"
+ {
+ "type": "map",
+ "key-id": 4,
+ "key": "int",
+ "value-id": 5,
+ "value-required": true,
+ "value": "string"
+ }
+ "#;
+
+ check_type_serde(
+ record,
+ Type::Map(MapType::required(
+ 4,
+ Type::Primitive(PrimitiveType::Int),
+ 5,
+ Type::Primitive(PrimitiveType::String),
+ )),
+ );
}
#[test]