in pyiceberg/catalog/__init__.py [0:0]
def load_catalog(name: Optional[str] = None, **properties: Optional[str]) -> Catalog:
"""Load the catalog based on the properties.
Will look up the properties from the config, based on the name.
Args:
name: The name of the catalog.
properties: The properties that are used next to the configuration.
Returns:
An initialized Catalog.
Raises:
ValueError: Raises a ValueError in case properties are missing or malformed,
or if it could not determine the catalog based on the properties.
"""
if name is None:
name = _ENV_CONFIG.get_default_catalog_name()
env = _ENV_CONFIG.get_catalog_config(name)
conf: RecursiveDict = merge_config(env or {}, cast(RecursiveDict, properties))
catalog_type: Optional[CatalogType]
provided_catalog_type = conf.get(TYPE)
if catalog_impl := properties.get(PY_CATALOG_IMPL):
if provided_catalog_type:
raise ValueError(
"Must not set both catalog type and py-catalog-impl configurations, "
f"but found type {provided_catalog_type} and py-catalog-impl {catalog_impl}"
)
if catalog := _import_catalog(name, catalog_impl, properties):
logger.info("Loaded Catalog: %s", catalog_impl)
return catalog
else:
raise ValueError(f"Could not initialize Catalog: {catalog_impl}")
catalog_type = None
if provided_catalog_type and isinstance(provided_catalog_type, str):
catalog_type = CatalogType[provided_catalog_type.upper()]
elif not provided_catalog_type:
catalog_type = infer_catalog_type(name, conf)
if catalog_type:
return AVAILABLE_CATALOGS[catalog_type](name, cast(Dict[str, str], conf))
raise ValueError(f"Could not initialize catalog with the following properties: {properties}")