Skip to content

Commit 933f256

Browse files
committed
test console with sqlcatalog
1 parent 36b56eb commit 933f256

File tree

3 files changed

+219
-163
lines changed

3 files changed

+219
-163
lines changed

pyiceberg/catalog/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ def identifier_to_database_and_table(
596596
) -> Tuple[str, str]:
597597
tuple_identifier = Catalog.identifier_to_tuple(identifier)
598598
if len(tuple_identifier) != 2:
599-
raise err(f"Invalid path, hierarchical namespaces are not supported: {identifier}")
599+
raise err(f"Table does not exist: {tuple_identifier}")
600600

601601
return tuple_identifier[0], tuple_identifier[1]
602602

pyiceberg/catalog/sql.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def create_table(
177177

178178
database_name, table_name = self.identifier_to_database_and_table(identifier)
179179
if not self._namespace_exists(database_name):
180-
raise NoSuchNamespaceError(f"Namespace does not exist: {database_name}")
180+
self.create_namespace(database_name)
181181

182182
location = self._resolve_table_location(location, database_name, table_name)
183183
metadata_location = self._get_metadata_location(location=location)
@@ -265,7 +265,7 @@ def load_table(self, identifier: Union[str, Identifier]) -> Table:
265265
result = session.scalar(stmt)
266266
if result:
267267
return self._convert_orm_to_iceberg(result)
268-
raise NoSuchTableError(f"Table does not exist: {database_name}.{table_name}")
268+
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}")
269269

270270
def drop_table(self, identifier: Union[str, Identifier]) -> None:
271271
"""Drop a table.
@@ -288,7 +288,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
288288
)
289289
)
290290
if res.rowcount < 1:
291-
raise NoSuchTableError(f"Table does not exist: {database_name}.{table_name}")
291+
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}")
292292
else:
293293
try:
294294
tbl = (
@@ -303,7 +303,7 @@ def drop_table(self, identifier: Union[str, Identifier]) -> None:
303303
)
304304
session.delete(tbl)
305305
except NoResultFound as e:
306-
raise NoSuchTableError(f"Table does not exist: {database_name}.{table_name}") from e
306+
raise NoSuchTableError(f"Table does not exist: {identifier_tuple}") from e
307307
session.commit()
308308

309309
def rename_table(self, from_identifier: Union[str, Identifier], to_identifier: Union[str, Identifier]) -> Table:
@@ -503,6 +503,8 @@ def drop_namespace(self, namespace: Union[str, Identifier]) -> None:
503503
)
504504
)
505505
session.commit()
506+
else:
507+
raise NoSuchNamespaceError(f"Namespace does not exist: {self.identifier_to_tuple(namespace)}")
506508

507509
def list_tables(self, namespace: Union[str, Identifier]) -> List[Identifier]:
508510
"""List tables under the given namespace in the catalog.
@@ -539,6 +541,10 @@ def list_namespaces(self, namespace: Union[str, Identifier] = ()) -> List[Identi
539541
Raises:
540542
NoSuchNamespaceError: If a namespace with the given name does not exist.
541543
"""
544+
# Hierarchical namespace is not supported. Return an empty list
545+
if namespace:
546+
return []
547+
542548
if namespace and not self._namespace_exists(namespace):
543549
raise NoSuchNamespaceError(f"Namespace does not exist: {namespace}")
544550

@@ -575,7 +581,9 @@ def load_namespace_properties(self, namespace: Union[str, Identifier]) -> Proper
575581
IcebergNamespaceProperties.catalog_name == self.name, IcebergNamespaceProperties.namespace == database_name
576582
)
577583
with Session(self.engine) as session:
578-
result = session.scalars(stmt)
584+
result = list(session.scalars(stmt))
585+
if len(result) == 0:
586+
raise NoSuchNamespaceError(f"Namespace does not exist: {namespace}")
579587
return {props.property_key: props.property_value for props in result}
580588

581589
def update_namespace_properties(
@@ -594,7 +602,7 @@ def update_namespace_properties(
594602
"""
595603
database_name = self.identifier_to_database(namespace)
596604
if not self._namespace_exists(database_name):
597-
raise NoSuchNamespaceError(f"Database {database_name} does not exists")
605+
raise NoSuchNamespaceError(f"Namespace does not exist: {self.identifier_to_tuple(namespace)}")
598606

599607
current_properties = self.load_namespace_properties(namespace=namespace)
600608
properties_update_summary = self._get_updated_props_and_update_summary(

0 commit comments

Comments
 (0)