marvinlanhenke commented on code in PR #237: URL: https://github.com/apache/iceberg-rust/pull/237#discussion_r1518564967
########## crates/catalog/hms/src/catalog.rs: ########## @@ -95,9 +106,156 @@ impl HmsCatalog { client: HmsClient(client), }) } + + /// Create and extract properties from `hive_metastore::hms::Database`. + pub fn properties_from_database(database: &Database) -> HashMap<String, String> { + let mut properties = HashMap::new(); + + if let Some(description) = &database.description { + properties.insert("comment".to_string(), description.to_string()); + }; + + if let Some(location) = &database.location_uri { + properties.insert("location".to_string(), location.to_string()); + }; + + if let Some(owner) = &database.owner_name { + properties.insert(HMS_DB_OWNER.to_string(), owner.to_string()); + }; + + if let Some(owner_type) = &database.owner_type { + let value = match owner_type { + PrincipalType::User => "User", + PrincipalType::Group => "Group", + PrincipalType::Role => "Role", + }; + + properties.insert(HMS_DB_OWNER_TYPE.to_string(), value.to_string()); + }; + + if let Some(params) = &database.parameters { + params.iter().for_each(|(k, v)| { + properties.insert(k.clone().into(), v.clone().into()); + }); + }; + + properties + } + + /// Converts name and properties into `hive_metastore::hms::Database` + /// after validating the `namespace` and `owner-settings`. + pub fn convert_to_database( Review Comment: I really like the idea. However, how would you handle the situation where I need to get the Database from the hive_metastore via the client. Fetching the db and then wrapping it with the new type simply to call `fn to_namespace` seems weird - but maybe there is another way to do this more elegantly? Perhaps, we can extend the HmsCatalog as well with the new type? This way I can fetch the DB with the client and set the db on HmsCatalog and call the conversion fns? ```rust pub struct HmsDatabase(Database); pub struct HmsCatalog { config: HmsCatalogConfig, client: HmsClient, database: HmsDatabase, } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org