Skip to content

Commit d9edcb5

Browse files
committed
Use NoSuchIdentifier instead of NoTableIdentifier
This change allows for the validation of both Tables and Views.
1 parent 9e27d59 commit d9edcb5

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
@@ -379,7 +380,7 @@ def _fetch_config(self) -> None:
379380
def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> Identifier:
380381
identifier_tuple = self.identifier_to_tuple(identifier)
381382
if len(identifier_tuple) <= 1:
382-
raise NoSuchTableError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
383+
raise NoSuchIdentifierError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
383384
return identifier_tuple
384385

385386
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
@@ -33,6 +33,7 @@
3333
NoSuchTableError,
3434
OAuthError,
3535
TableAlreadyExistsError,
36+
NoSuchIdentifierError,
3637
)
3738
from pyiceberg.io import load_file_io
3839
from pyiceberg.partitioning import PartitionField, PartitionSpec
@@ -1099,31 +1100,31 @@ def test_delete_table_404(rest_mock: Mocker) -> None:
10991100

11001101
def test_create_table_missing_namespace(rest_mock: Mocker, table_schema_simple: Schema) -> None:
11011102
table = "table"
1102-
with pytest.raises(NoSuchTableError) as e:
1103+
with pytest.raises(NoSuchIdentifierError) as e:
11031104
# Missing namespace
11041105
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).create_table(table, table_schema_simple)
11051106
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11061107

11071108

11081109
def test_load_table_invalid_namespace(rest_mock: Mocker) -> None:
11091110
table = "table"
1110-
with pytest.raises(NoSuchTableError) as e:
1111+
with pytest.raises(NoSuchIdentifierError) as e:
11111112
# Missing namespace
11121113
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).load_table(table)
11131114
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11141115

11151116

11161117
def test_drop_table_invalid_namespace(rest_mock: Mocker) -> None:
11171118
table = "table"
1118-
with pytest.raises(NoSuchTableError) as e:
1119+
with pytest.raises(NoSuchIdentifierError) as e:
11191120
# Missing namespace
11201121
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_table(table)
11211122
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11221123

11231124

11241125
def test_purge_table_invalid_namespace(rest_mock: Mocker) -> None:
11251126
table = "table"
1126-
with pytest.raises(NoSuchTableError) as e:
1127+
with pytest.raises(NoSuchIdentifierError) as e:
11271128
# Missing namespace
11281129
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).purge_table(table)
11291130
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)

0 commit comments

Comments
 (0)