@@ -588,7 +588,7 @@ def identifier_to_tuple(identifier: Union[str, Identifier]) -> Identifier:
588
588
If the identifier is a string, it is split into a tuple on '.'. If it is a tuple, it is used as-is.
589
589
590
590
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.
592
592
593
593
Returns:
594
594
Identifier: a tuple of strings.
@@ -619,6 +619,29 @@ def namespace_from(identifier: Union[str, Identifier]) -> Identifier:
619
619
"""
620
620
return Catalog .identifier_to_tuple (identifier )[:- 1 ]
621
621
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
+
622
645
@staticmethod
623
646
def identifier_to_database (
624
647
identifier : Union [str , Identifier ], err : Union [Type [ValueError ], Type [NoSuchNamespaceError ]] = ValueError
0 commit comments