Skip to content

Commit 9881f11

Browse files
committed
Use NoSuchIdentifier instead of NoTableIdentifier
This change allows for the validation of both Tables and Views.
1 parent e4c1748 commit 9881f11

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pyiceberg/catalog/rest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
ServiceUnavailableError,
5757
TableAlreadyExistsError,
5858
UnauthorizedError,
59+
NoSuchIdentifierError,
5960
)
6061
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec, assign_fresh_partition_spec_ids
6162
from pyiceberg.schema import Schema, assign_fresh_schema_ids
@@ -389,7 +390,7 @@ def _fetch_config(self) -> None:
389390
def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> Identifier:
390391
identifier_tuple = self.identifier_to_tuple(identifier)
391392
if len(identifier_tuple) <= 1:
392-
raise NoSuchTableError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
393+
raise NoSuchIdentifierError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
393394
return identifier_tuple
394395

395396
def _split_identifier_for_path(self, identifier: Union[str, Identifier, TableIdentifier]) -> Properties:

pyiceberg/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ class NoSuchIcebergTableError(NoSuchTableError):
4040
"""Raises when the table found in the REST catalog is not an iceberg table."""
4141

4242

43+
44+
45+
class NoSuchIdentifierError(Exception):
46+
"""Raises when the identifier can't be found in the REST catalog."""
47+
48+
4349
class NoSuchNamespaceError(Exception):
4450
"""Raised when a referenced name-space is not found."""
4551

tests/catalog/test_rest.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
OAuthError,
3535
ServerError,
3636
TableAlreadyExistsError,
37+
NoSuchIdentifierError,
3738
)
3839
from pyiceberg.io import load_file_io
3940
from pyiceberg.partitioning import PartitionField, PartitionSpec
@@ -1158,31 +1159,31 @@ def test_delete_table_404(rest_mock: Mocker) -> None:
11581159

11591160
def test_create_table_missing_namespace(rest_mock: Mocker, table_schema_simple: Schema) -> None:
11601161
table = "table"
1161-
with pytest.raises(NoSuchTableError) as e:
1162+
with pytest.raises(NoSuchIdentifierError) as e:
11621163
# Missing namespace
11631164
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).create_table(table, table_schema_simple)
11641165
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11651166

11661167

11671168
def test_load_table_invalid_namespace(rest_mock: Mocker) -> None:
11681169
table = "table"
1169-
with pytest.raises(NoSuchTableError) as e:
1170+
with pytest.raises(NoSuchIdentifierError) as e:
11701171
# Missing namespace
11711172
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).load_table(table)
11721173
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11731174

11741175

11751176
def test_drop_table_invalid_namespace(rest_mock: Mocker) -> None:
11761177
table = "table"
1177-
with pytest.raises(NoSuchTableError) as e:
1178+
with pytest.raises(NoSuchIdentifierError) as e:
11781179
# Missing namespace
11791180
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_table(table)
11801181
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11811182

11821183

11831184
def test_purge_table_invalid_namespace(rest_mock: Mocker) -> None:
11841185
table = "table"
1185-
with pytest.raises(NoSuchTableError) as e:
1186+
with pytest.raises(NoSuchIdentifierError) as e:
11861187
# Missing namespace
11871188
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).purge_table(table)
11881189
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)

0 commit comments

Comments
 (0)