This is an automated email from the ASF dual-hosted git repository.

kevinjqliu pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg-python.git


The following commit(s) were added to refs/heads/main by this push:
     new 8bfb16cf fix loading `in-memory` catalog (#1725)
8bfb16cf is described below

commit 8bfb16cf063d121a177d43fec01620e1a5e6d84a
Author: Kevin Liu <[email protected]>
AuthorDate: Tue Feb 25 21:09:51 2025 -0500

    fix loading `in-memory` catalog (#1725)
    
    Previously `CatalogType` was fetched by key,
    `CatalogType[provided_catalog_type.upper()]` (note the bracket)
    This PR changes `CatalogType` to be fetched by value,
    `CatalogType(provided_catalog_type.lower())` (note the parenthesis)
    
    
    
https://stackoverflow.com/questions/29799235/python-enum-value2member-map-accessor
    
    This fix loading `in-memory` catalog, `load_catalog("catalog",
    **{"type": "in-memory"})`.
    Previously, `"in-memory"` caused a key error because its key is
    `IN_MEMORY`. Note the `-` vs `_`.
    
    
    
https://github.com/apache/iceberg-python/blob/1d24e71041e35e26e126aa4508ed7384e8aa031c/pyiceberg/catalog/__init__.py#L113-L119
    
    
    We want `in-memory` and not `in_memory` to match spark
    
    
https://github.com/apache/iceberg-python/blob/1d24e71041e35e26e126aa4508ed7384e8aa031c/dev/spark-defaults.conf#L35
---
 pyiceberg/catalog/__init__.py | 2 +-
 tests/catalog/test_base.py    | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/pyiceberg/catalog/__init__.py b/pyiceberg/catalog/__init__.py
index 01dd228e..cf649ba7 100644
--- a/pyiceberg/catalog/__init__.py
+++ b/pyiceberg/catalog/__init__.py
@@ -252,7 +252,7 @@ def load_catalog(name: Optional[str] = None, **properties: 
Optional[str]) -> Cat
 
     catalog_type = None
     if provided_catalog_type and isinstance(provided_catalog_type, str):
-        catalog_type = CatalogType[provided_catalog_type.upper()]
+        catalog_type = CatalogType(provided_catalog_type.lower())
     elif not provided_catalog_type:
         catalog_type = infer_catalog_type(name, conf)
 
diff --git a/tests/catalog/test_base.py b/tests/catalog/test_base.py
index c00f4fde..6e00bfec 100644
--- a/tests/catalog/test_base.py
+++ b/tests/catalog/test_base.py
@@ -88,6 +88,10 @@ def given_catalog_has_a_table(
     )
 
 
+def test_load_catalog_in_memory() -> None:
+    assert load_catalog("catalog", type="in-memory")
+
+
 def test_load_catalog_impl_not_full_path() -> None:
     with pytest.raises(ValueError) as exc_info:
         load_catalog("catalog", **{"py-catalog-impl": "CustomCatalog"})

Reply via email to