Skip to content

Commit 53ceb2b

Browse files
authored
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.
1 parent e1e3ba4 commit 53ceb2b

File tree

1 file changed

+23
-1
lines changed
  • crates/iceberg/src/catalog

1 file changed

+23
-1
lines changed

crates/iceberg/src/catalog/mod.rs

+23-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,9 @@ pub struct TableCreation {
261261
#[builder(default, setter(strip_option(fallback = sort_order_opt)))]
262262
pub sort_order: Option<SortOrder>,
263263
/// The properties of the table.
264-
#[builder(default)]
264+
#[builder(default, setter(transform = |props: impl IntoIterator<Item=(String, String)>| {
265+
props.into_iter().collect()
266+
}))]
265267
pub properties: HashMap<String, String>,
266268
}
267269

@@ -901,6 +903,26 @@ mod tests {
901903
assert_eq!(table_id, TableIdent::from_strs(vec!["ns1", "t1"]).unwrap());
902904
}
903905

906+
#[test]
907+
fn test_table_creation_iterator_properties() {
908+
let builder = TableCreation::builder()
909+
.name("table".to_string())
910+
.schema(Schema::builder().build().unwrap());
911+
912+
fn s(k: &str, v: &str) -> (String, String) {
913+
(k.to_string(), v.to_string())
914+
}
915+
916+
let table_creation = builder
917+
.properties([s("key", "value"), s("foo", "bar")])
918+
.build();
919+
920+
assert_eq!(
921+
HashMap::from([s("key", "value"), s("foo", "bar")]),
922+
table_creation.properties
923+
);
924+
}
925+
904926
fn test_serde_json<T: Serialize + DeserializeOwned + PartialEq + Debug>(
905927
json: impl ToString,
906928
expected: T,

0 commit comments

Comments
 (0)