From ddb0795e662a5ddd085a89dc13eb448ecc453968 Mon Sep 17 00:00:00 2001 From: Zhang Yanpo Date: Tue, 22 Apr 2025 11:23:56 +0800 Subject: [PATCH] refactor: TableCreation::builder()::properties accepts an `IntoIterator` `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`. --- 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 e57152abc0..6a1572a4af 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, /// The properties of the table. - #[builder(default)] + #[builder(default, setter(transform = |props: impl IntoIterator| { + props.into_iter().collect() + }))] pub properties: HashMap, } @@ -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( json: impl ToString, expected: T,