You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iceberg.apache.org by li...@apache.org on 2025/04/22 07:17:57 UTC
(iceberg-rust) branch main updated: refactor: TableCreation::builder()::properties accept an `IntoIterator` (#1233)
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 53ceb2b5 refactor: TableCreation::builder()::properties accept an `IntoIterator` (#1233)
53ceb2b5 is described below
commit 53ceb2b5426f56efd1152a9daaa2fca25847b6ff
Author: 张炎泼 <dr...@gmail.com>
AuthorDate: Tue Apr 22 19:17:52 2025 +1200
refactor: TableCreation::builder()::properties accept an `IntoIterator` (#1233)
## What changes are included in this PR?
`TableCreation::builder().properties()` should be able to accept any
`IntoIterator` type that can be used to build an `HashMap`.
For example, `TableCreation::builder().properties([("foo".to_string(),
"bar".to_string())])` should build a `HashMap` with one key value pair
`foo -> bar`.
## Are these changes tested?
Unittest are provided.
---
crates/iceberg/src/catalog/mod.rs | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/crates/iceberg/src/catalog/mod.rs b/crates/iceberg/src/catalog/mod.rs
index e57152ab..6a1572a4 100644
--- a/crates/iceberg/src/catalog/mod.rs
+++ b/crates/iceberg/src/catalog/mod.rs
@@ -261,7 +261,9 @@ pub struct TableCreation {
#[builder(default, setter(strip_option(fallback = sort_order_opt)))]
pub sort_order: Option<SortOrder>,
/// The properties of the table.
- #[builder(default)]
+ #[builder(default, setter(transform = |props: impl IntoIterator<Item=(String, String)>| {
+ props.into_iter().collect()
+ }))]
pub properties: HashMap<String, String>,
}
@@ -901,6 +903,26 @@ mod tests {
assert_eq!(table_id, TableIdent::from_strs(vec!["ns1", "t1"]).unwrap());
}
+ #[test]
+ fn test_table_creation_iterator_properties() {
+ let builder = TableCreation::builder()
+ .name("table".to_string())
+ .schema(Schema::builder().build().unwrap());
+
+ fn s(k: &str, v: &str) -> (String, String) {
+ (k.to_string(), v.to_string())
+ }
+
+ let table_creation = builder
+ .properties([s("key", "value"), s("foo", "bar")])
+ .build();
+
+ assert_eq!(
+ HashMap::from([s("key", "value"), s("foo", "bar")]),
+ table_creation.properties
+ );
+ }
+
fn test_serde_json<T: Serialize + DeserializeOwned + PartialEq + Debug>(
json: impl ToString,
expected: T,