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 2026/09/02 09:29:06 UTC
(iceberg-rust) branch main updated: refactor(memory): derive catalog configuration from properties (#3101)
This is an automated email from the ASF dual-hosted git repository.
blackmwk 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 6d65786d7 refactor(memory): derive catalog configuration from properties (#3101)
6d65786d7 is described below
commit 6d65786d7a4e19d6e62ac6b5df79e88841eae7be
Author: blackmwk <25...@users.noreply.github.com>
AuthorDate: Wed Sep 2 17:29:00 2026 +0800
refactor(memory): derive catalog configuration from properties (#3101)
* refactor(memory): derive catalog configuration from properties
Replace manual catalog property extraction with the shared derive while preserving warehouse validation and forwarding unmodeled properties.
Tracks [apache/iceberg-rust#3095](https://github.com/apache/iceberg-rust/issues/3095).
Generated-by: Codex
* refactor(memory): retain typed catalog properties
Remove the redundant config wrapper and catch-all property field, expose the typed properties, and retain the catalog name and typed properties on MemoryCatalog.
Addresses review feedback on [apache/iceberg-rust#3101](https://github.com/apache/iceberg-rust/pull/3101).
Generated-by: Codex
* refactor(memory): retain raw catalog properties
* fix(memory): defer missing warehouse validation
* refactor(memory): move raw properties into file io
* fix(memory): restore catalog validation contract
* refactor(memory): retain public catalog properties
* refactor(memory): forward raw catalog properties
---
crates/iceberg/public-api.txt | 2 +-
crates/iceberg/src/catalog/memory/catalog.rs | 185 +++++++++++++++++----------
2 files changed, 120 insertions(+), 67 deletions(-)
diff --git a/crates/iceberg/public-api.txt b/crates/iceberg/public-api.txt
index 4aeddb665..d61912c90 100644
--- a/crates/iceberg/public-api.txt
+++ b/crates/iceberg/public-api.txt
@@ -1112,7 +1112,7 @@ pub fn iceberg::memory::MemoryCatalog::update_namespace<'life0, 'life1, 'async_t
pub fn iceberg::memory::MemoryCatalog::update_table<'life0, 'async_trait>(&'life0 self, commit: iceberg::TableCommit) -> core::pin::Pin<alloc::boxed::Box<(dyn core::future::future::Future<Output = iceberg::Result<iceberg::table::Table>> + core::marker::Send + 'async_trait)>> where Self: 'async_trait, 'life0: 'async_trait
pub struct iceberg::memory::MemoryCatalogBuilder
impl core::default::Default for iceberg::memory::MemoryCatalogBuilder
-pub fn iceberg::memory::MemoryCatalogBuilder::default() -> Self
+pub fn iceberg::memory::MemoryCatalogBuilder::default() -> iceberg::memory::MemoryCatalogBuilder
impl core::fmt::Debug for iceberg::memory::MemoryCatalogBuilder
pub fn iceberg::memory::MemoryCatalogBuilder::fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result
impl iceberg::CatalogBuilder for iceberg::memory::MemoryCatalogBuilder
diff --git a/crates/iceberg/src/catalog/memory/catalog.rs b/crates/iceberg/src/catalog/memory/catalog.rs
index 85fcd824e..aae0f7d5a 100644
--- a/crates/iceberg/src/catalog/memory/catalog.rs
+++ b/crates/iceberg/src/catalog/memory/catalog.rs
@@ -23,6 +23,7 @@ use std::sync::Arc;
use async_trait::async_trait;
use futures::lock::{Mutex, MutexGuard};
+use iceberg_property_macro::Properties;
use itertools::Itertools;
use super::namespace_state::NamespaceState;
@@ -43,29 +44,13 @@ pub const MEMORY_CATALOG_WAREHOUSE: &str = "warehouse";
const LOCATION: &str = "location";
/// Builder for [`MemoryCatalog`].
-#[derive(Debug)]
+#[derive(Debug, Default)]
pub struct MemoryCatalogBuilder {
- config: MemoryCatalogConfig,
storage_factory: Option<Arc<dyn StorageFactory>>,
kms_client_factory: Option<Arc<dyn KmsClientFactory>>,
runtime: Option<Runtime>,
}
-impl Default for MemoryCatalogBuilder {
- fn default() -> Self {
- Self {
- config: MemoryCatalogConfig {
- name: None,
- warehouse: "".to_string(),
- props: HashMap::new(),
- },
- storage_factory: None,
- kms_client_factory: None,
- runtime: None,
- }
- }
-}
-
impl CatalogBuilder for MemoryCatalogBuilder {
type C = MemoryCatalog;
@@ -85,69 +70,70 @@ impl CatalogBuilder for MemoryCatalogBuilder {
}
fn load(
- mut self,
+ self,
name: impl Into<String>,
props: HashMap<String, String>,
) -> impl Future<Output = Result<Self::C>> + Send {
- self.config.name = Some(name.into());
-
- if props.contains_key(MEMORY_CATALOG_WAREHOUSE) {
- self.config.warehouse = props
- .get(MEMORY_CATALOG_WAREHOUSE)
- .cloned()
- .unwrap_or_default()
- }
-
- // Collect other remaining properties
- self.config.props = props
- .into_iter()
- .filter(|(k, _)| k != MEMORY_CATALOG_WAREHOUSE)
- .collect();
+ let name = name.into();
async move {
- if self.config.name.is_none() {
- Err(Error::new(
- ErrorKind::DataInvalid,
- "Catalog name is required",
- ))
- } else if self.config.warehouse.is_empty() {
- Err(Error::new(
+ let catalog_properties = MemoryCatalogProperties::from_properties(&props)?;
+ if catalog_properties.warehouse.is_empty() {
+ return Err(Error::new(
ErrorKind::DataInvalid,
"Catalog warehouse is required",
- ))
- } else {
- let runtime = self.runtime.unwrap_or_else(Runtime::current);
- let kms_client = match self.kms_client_factory {
- Some(factory) => Some(factory.create_kms_client(&self.config.props).await?),
- None => None,
- };
- MemoryCatalog::new(self.config, self.storage_factory, runtime, kms_client)
+ ));
}
+
+ let runtime = self.runtime.unwrap_or_else(Runtime::current);
+ let kms_client = match self.kms_client_factory {
+ Some(factory) => Some(factory.create_kms_client(&props).await?),
+ None => None,
+ };
+ MemoryCatalog::new(
+ name,
+ catalog_properties,
+ props,
+ self.storage_factory,
+ runtime,
+ kms_client,
+ )
}
}
}
-#[derive(Clone, Debug)]
-pub(crate) struct MemoryCatalogConfig {
- name: Option<String>,
+/// Memory catalog properties parsed from a catalog property map.
+#[derive(Debug, Properties)]
+pub(crate) struct MemoryCatalogProperties {
+ #[property(key = MEMORY_CATALOG_WAREHOUSE, default = "")]
warehouse: String,
- props: HashMap<String, String>,
}
/// Memory catalog implementation.
-#[derive(Debug)]
pub struct MemoryCatalog {
+ name: String,
+ properties: MemoryCatalogProperties,
root_namespace_state: Mutex<NamespaceState>,
file_io: FileIO,
- warehouse_location: String,
runtime: Runtime,
kms_client: Option<Arc<dyn KeyManagementClient>>,
}
+impl std::fmt::Debug for MemoryCatalog {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ f.debug_struct("MemoryCatalog")
+ .field("name", &self.name)
+ .field("properties", &self.properties)
+ .finish_non_exhaustive()
+ }
+}
+
impl MemoryCatalog {
/// Creates a memory catalog.
fn new(
- config: MemoryCatalogConfig,
+ name: String,
+ properties: MemoryCatalogProperties,
+ props: HashMap<String, String>,
storage_factory: Option<Arc<dyn StorageFactory>>,
runtime: Runtime,
kms_client: Option<Arc<dyn KeyManagementClient>>,
@@ -156,9 +142,10 @@ impl MemoryCatalog {
let factory = storage_factory.unwrap_or_else(|| Arc::new(MemoryStorageFactory));
Ok(Self {
+ name,
+ properties,
+ file_io: FileIOBuilder::new(factory).with_props(props).build(),
root_namespace_state: Mutex::new(NamespaceState::default()),
- file_io: FileIOBuilder::new(factory).with_props(config.props).build(),
- warehouse_location: config.warehouse,
runtime,
kms_client,
})
@@ -308,7 +295,11 @@ impl Catalog for MemoryCatalog {
let namespace_properties = root_namespace_state.get_properties(namespace_ident)?;
let location_prefix = match namespace_properties.get(LOCATION) {
Some(namespace_location) => namespace_location.clone(),
- None => format!("{}/{}", self.warehouse_location, namespace_ident.join("/")),
+ None => format!(
+ "{}/{}",
+ self.properties.warehouse,
+ namespace_ident.join("/")
+ ),
};
let location = format!("{}/{}", location_prefix, table_ident.name());
@@ -458,6 +449,57 @@ pub(crate) mod tests {
temp_dir.path().to_str().unwrap().to_string()
}
+ #[test]
+ fn test_catalog_properties() {
+ let properties = MemoryCatalogProperties::from_properties(&HashMap::from([(
+ MEMORY_CATALOG_WAREHOUSE.to_string(),
+ "memory:///warehouse".to_string(),
+ )]))
+ .unwrap();
+
+ assert_eq!(properties.warehouse, "memory:///warehouse");
+ }
+
+ #[test]
+ fn test_catalog_properties_warehouse_defaults_to_empty() {
+ let missing = MemoryCatalogProperties::from_properties(&HashMap::new()).unwrap();
+ let explicitly_empty = MemoryCatalogProperties::from_properties(&HashMap::from([(
+ MEMORY_CATALOG_WAREHOUSE.to_string(),
+ String::new(),
+ )]))
+ .unwrap();
+
+ assert_eq!(missing.warehouse, "");
+ assert_eq!(explicitly_empty.warehouse, "");
+ }
+
+ #[tokio::test]
+ async fn test_catalog_forwards_properties_to_file_io() {
+ let catalog = MemoryCatalogBuilder::default()
+ .load(
+ "memory",
+ HashMap::from([
+ (
+ MEMORY_CATALOG_WAREHOUSE.to_string(),
+ "memory:///warehouse".to_string(),
+ ),
+ ("custom.property".to_string(), "value".to_string()),
+ ]),
+ )
+ .await
+ .unwrap();
+ let file_io_props = catalog.file_io.config().props();
+
+ assert_eq!(
+ file_io_props.get("custom.property"),
+ Some(&"value".to_string())
+ );
+ assert_eq!(
+ file_io_props.get(MEMORY_CATALOG_WAREHOUSE),
+ Some(&"memory:///warehouse".to_string())
+ );
+ }
+
pub(crate) async fn new_memory_catalog() -> impl Catalog {
let warehouse_location = temp_path();
MemoryCatalogBuilder::default()
@@ -1401,17 +1443,28 @@ pub(crate) mod tests {
}
#[tokio::test]
- async fn test_create_table_throws_error_if_table_location_and_namespace_location_and_warehouse_location_are_missing()
- {
- let catalog = MemoryCatalogBuilder::default()
+ async fn test_load_throws_error_if_warehouse_is_missing() {
+ let error = MemoryCatalogBuilder::default()
.load("memory", HashMap::from([]))
- .await;
+ .await
+ .unwrap_err();
- assert!(catalog.is_err());
- assert_eq!(
- catalog.unwrap_err().to_string(),
- "DataInvalid => Catalog warehouse is required"
- );
+ assert_eq!(error.kind(), ErrorKind::DataInvalid);
+ assert_eq!(error.message(), "Catalog warehouse is required");
+ }
+
+ #[tokio::test]
+ async fn test_load_throws_error_if_warehouse_is_empty() {
+ let error = MemoryCatalogBuilder::default()
+ .load(
+ "memory",
+ HashMap::from([(MEMORY_CATALOG_WAREHOUSE.to_string(), String::new())]),
+ )
+ .await
+ .unwrap_err();
+
+ assert_eq!(error.kind(), ErrorKind::DataInvalid);
+ assert_eq!(error.message(), "Catalog warehouse is required");
}
#[tokio::test]