@@ -489,16 +489,22 @@ def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: U
489489 raise NoSuchNamespaceError (f"Database does not exists: { to_database_name } " ) from e
490490 return self .load_table (to_identifier )
491491
492- def create_namespace (self , namespace : Union [str , Identifier ], properties : Properties = EMPTY_DICT ) -> None :
492+ def create_namespace (
493+ self ,
494+ namespace : Union [str , Identifier ],
495+ properties : Properties = EMPTY_DICT ,
496+ error_if_exists : bool = True ,
497+ ) -> None :
493498 """Create a namespace in the catalog.
494499
495500 Args:
496501 namespace: Namespace identifier.
497502 properties: A string dictionary of properties for the given namespace.
503+ error_if_exists (bool): If True, raise an error when the namespace already exists. Default is True.
498504
499505 Raises:
500506 ValueError: If the identifier is invalid.
501- AlreadyExistsError : If a namespace with the given name already exists.
507+ NamespaceAlreadyExistsError : If a namespace with the given name already exists and error_if_exist is True .
502508 """
503509 database_name = self .identifier_to_database (namespace )
504510 hive_database = HiveDatabase (name = database_name , parameters = properties )
@@ -507,6 +513,8 @@ def create_namespace(self, namespace: Union[str, Identifier], properties: Proper
507513 with self ._client as open_client :
508514 open_client .create_database (_annotate_namespace (hive_database , properties ))
509515 except AlreadyExistsException as e :
516+ if not error_if_exists :
517+ return
510518 raise NamespaceAlreadyExistsError (f"Database { database_name } already exists" ) from e
511519
512520 def drop_namespace (self , namespace : Union [str , Identifier ]) -> None :
0 commit comments