Skip to content

Commit

Permalink
Introduce hierarchical namespaces into SqlCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
cccs-eric committed Apr 8, 2024
1 parent ee4dd92 commit c6b5177
Show file tree
Hide file tree
Showing 5 changed files with 726 additions and 282 deletions.
25 changes: 24 additions & 1 deletion pyiceberg/catalog/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
If the identifier is a string, it is split into a tuple on '.'. If it is a tuple, it is used as-is.
Args:
identifier (str | Identifier: an identifier, either a string or tuple of strings.
identifier (str | Identifier): an identifier, either a string or tuple of strings.
Returns:
Identifier: a tuple of strings.
Expand Down Expand Up @@ -600,6 +600,29 @@ def namespace_from(identifier: Union[str, Identifier]) -> Identifier:
"""
return Catalog.identifier_to_tuple(identifier)[:-1]

@staticmethod
def namespace_to_string(
identifier: Union[str, Identifier], err: Union[Type[ValueError], Type[NoSuchNamespaceError]] = ValueError
) -> str:
"""Transform a namespace identifier into a string.
Args:
identifier (Union[str, Identifier]): a namespace identifier.
err (Union[Type[ValueError], Type[NoSuchNamespaceError]]): the error type to raise when identifier is empty.
Returns:
Identifier: Namespace identifier.
"""
tuple_identifier = Catalog.identifier_to_tuple(identifier)
if len(tuple_identifier) < 1:
raise err("Empty namespace identifier")

# Check if any segment of the tuple is an empty string
if any(segment.strip() == "" for segment in tuple_identifier):
raise err("Namespace identifier contains an empty segment or a segment with only whitespace")

return ".".join(segment.strip() for segment in tuple_identifier)

@staticmethod
def identifier_to_database(
identifier: Union[str, Identifier], err: Union[Type[ValueError], Type[NoSuchNamespaceError]] = ValueError
Expand Down
Loading

0 comments on commit c6b5177

Please sign in to comment.