Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/catalog/glue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ async-trait = { workspace = true }
aws-config = { workspace = true }
aws-sdk-glue = { workspace = true }
iceberg = { workspace = true }
iceberg-property-macro = { workspace = true }
iceberg-storage-opendal = { workspace = true, features = ["opendal-s3"] }
serde_json = { workspace = true }
tokio = { workspace = true }
Expand Down
81 changes: 56 additions & 25 deletions crates/catalog/glue/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use iceberg::{
Catalog, CatalogBuilder, Error, ErrorKind, MetadataLocation, Namespace, NamespaceIdent, Result,
Runtime, TableCommit, TableCreation, TableIdent,
};
use iceberg_property_macro::Properties;
use iceberg_storage_opendal::OpenDalStorageFactory;

use crate::error::{from_aws_build_error, from_aws_sdk_error};
Expand Down Expand Up @@ -105,32 +106,20 @@ impl CatalogBuilder for GlueCatalogBuilder {
) -> impl Future<Output = Result<Self::C>> + Send {
self.config.name = Some(name.into());

if props.contains_key(GLUE_CATALOG_PROP_URI) {
self.config.uri = props.get(GLUE_CATALOG_PROP_URI).cloned()
}

if props.contains_key(GLUE_CATALOG_PROP_CATALOG_ID) {
self.config.catalog_id = props.get(GLUE_CATALOG_PROP_CATALOG_ID).cloned()
}

if props.contains_key(GLUE_CATALOG_PROP_WAREHOUSE) {
self.config.warehouse = props
.get(GLUE_CATALOG_PROP_WAREHOUSE)
.cloned()
.unwrap_or_default();
}

// Collect other remaining properties
self.config.props = props
.into_iter()
.filter(|(k, _)| {
k != GLUE_CATALOG_PROP_URI
&& k != GLUE_CATALOG_PROP_CATALOG_ID
&& k != GLUE_CATALOG_PROP_WAREHOUSE
})
.collect();

async move {
let mut catalog_properties = GlueCatalogProperties::from_properties(&props)?;
for property in [
GLUE_CATALOG_PROP_URI,
GLUE_CATALOG_PROP_CATALOG_ID,
GLUE_CATALOG_PROP_WAREHOUSE,
] {
catalog_properties.props.remove(property);
}
self.config.uri = catalog_properties.uri;
self.config.catalog_id = catalog_properties.catalog_id;
self.config.warehouse = catalog_properties.warehouse;
self.config.props = catalog_properties.props;

if self.config.name.is_none() {
return Err(Error::new(
ErrorKind::DataInvalid,
Expand All @@ -157,6 +146,48 @@ impl CatalogBuilder for GlueCatalogBuilder {
}
}

#[derive(Properties)]
struct GlueCatalogProperties {
#[property(key = GLUE_CATALOG_PROP_URI, default = None)]
uri: Option<String>,
#[property(key = GLUE_CATALOG_PROP_CATALOG_ID, default = None)]
catalog_id: Option<String>,
#[property(key = GLUE_CATALOG_PROP_WAREHOUSE, default = "")]
warehouse: String,
#[property(prefix = "")]
props: HashMap<String, String>,
}

#[cfg(test)]
mod catalog_properties_tests {
use super::*;

#[test]
fn test_catalog_properties() {
let properties = GlueCatalogProperties::from_properties(&HashMap::from([
(
GLUE_CATALOG_PROP_URI.to_string(),
"http://localhost".to_string(),
),
(
GLUE_CATALOG_PROP_CATALOG_ID.to_string(),
"catalog".to_string(),
),
(
GLUE_CATALOG_PROP_WAREHOUSE.to_string(),
"s3://warehouse".to_string(),
),
("aws_region".to_string(), "us-east-1".to_string()),
]))
.unwrap();

assert_eq!(properties.uri.as_deref(), Some("http://localhost"));
assert_eq!(properties.catalog_id.as_deref(), Some("catalog"));
assert_eq!(properties.warehouse, "s3://warehouse");
assert_eq!(properties.props["aws_region"], "us-east-1");
}
}

#[derive(Debug)]
/// Glue Catalog configuration
pub(crate) struct GlueCatalogConfig {
Expand Down
Loading