Skip to content

Commit 756ae62

Browse files
authored
Introduce hierarchical namespaces into SqlCatalog (#591)
* Introduce hierarchical namespaces into SqlCatalog * Fix SqlCatalog unit tests broken from code update.
1 parent 54aacb4 commit 756ae62

File tree

5 files changed

+758
-294
lines changed

5 files changed

+758
-294
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
588588
If the identifier is a string, it is split into a tuple on '.'. If it is a tuple, it is used as-is.
589589
590590
Args:
591-
identifier (str | Identifier: an identifier, either a string or tuple of strings.
591+
identifier (str | Identifier): an identifier, either a string or tuple of strings.
592592
593593
Returns:
594594
Identifier: a tuple of strings.
@@ -619,6 +619,29 @@ def namespace_from(identifier: Union[str, Identifier]) -> Identifier:
619619
"""
620620
return Catalog.identifier_to_tuple(identifier)[:-1]
621621

622+
@staticmethod
623+
def namespace_to_string(
624+
identifier: Union[str, Identifier], err: Union[Type[ValueError], Type[NoSuchNamespaceError]] = ValueError
625+
) -> str:
626+
"""Transform a namespace identifier into a string.
627+
628+
Args:
629+
identifier (Union[str, Identifier]): a namespace identifier.
630+
err (Union[Type[ValueError], Type[NoSuchNamespaceError]]): the error type to raise when identifier is empty.
631+
632+
Returns:
633+
Identifier: Namespace identifier.
634+
"""
635+
tuple_identifier = Catalog.identifier_to_tuple(identifier)
636+
if len(tuple_identifier) < 1:
637+
raise err("Empty namespace identifier")
638+
639+
# Check if any segment of the tuple is an empty string
640+
if any(segment.strip() == "" for segment in tuple_identifier):
641+
raise err("Namespace identifier contains an empty segment or a segment with only whitespace")
642+
643+
return ".".join(segment.strip() for segment in tuple_identifier)
644+
622645
@staticmethod
623646
def identifier_to_database(
624647
identifier: Union[str, Identifier], err: Union[Type[ValueError], Type[NoSuchNamespaceError]] = ValueError

0 commit comments

Comments
 (0)