Fokko commented on code in PR #1629:
URL: https://github.com/apache/iceberg-python/pull/1629#discussion_r1956607961


##########
pyiceberg/catalog/sql.py:
##########
@@ -610,15 +610,26 @@ def list_namespaces(self, namespace: Union[str, 
Identifier] = ()) -> List[Identi
         table_stmt = 
select(IcebergTables.table_namespace).where(IcebergTables.catalog_name == 
self.name)
         namespace_stmt = 
select(IcebergNamespaceProperties.namespace).where(IcebergNamespaceProperties.catalog_name
 == self.name)
         if namespace:
-            namespace_str = Catalog.namespace_to_string(namespace, 
NoSuchNamespaceError)
-            table_stmt = 
table_stmt.where(IcebergTables.table_namespace.like(namespace_str))
-            namespace_stmt = 
namespace_stmt.where(IcebergNamespaceProperties.namespace.like(namespace_str))
+            namespace_like = Catalog.namespace_to_string(namespace, 
NoSuchNamespaceError) + "%"
+            table_stmt = 
table_stmt.where(IcebergTables.table_namespace.like(namespace_like))
+            namespace_stmt = 
namespace_stmt.where(IcebergNamespaceProperties.namespace.like(namespace_like))
         stmt = union(
             table_stmt,
             namespace_stmt,
         )
         with Session(self.engine) as session:
-            return [Catalog.identifier_to_tuple(namespace_col) for 
namespace_col in session.execute(stmt).scalars()]
+            namespaces = [Catalog.identifier_to_tuple(namespace_col) for 
namespace_col in session.execute(stmt).scalars()]
+            sub_namespaces_level_length = 
len(Catalog.identifier_to_tuple(namespace)) + 1 if namespace else 1
+
+            # only get sub namespaces/children
+            namespaces = list({ns[:sub_namespaces_level_length] for ns in 
namespaces if len(ns) >= sub_namespaces_level_length})
+
+            if namespace:
+                namespace_tuple = Catalog.identifier_to_tuple(namespace)
+                # exclude fuzzy matches when `namespace` contains `%` or `_`
+                namespaces = [ns for ns in namespaces if ns[: 
len(namespace_tuple)] == namespace_tuple]

Review Comment:
   Performance nit: Should we move the `len` out of the loop?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to