Skip to content

Commit 88de9ad

Browse files
committed
Use NoSuchIdentifier instead of NoTableIdentifier
This change allows for the validation of both Tables and Views.
1 parent 5c9fa7e commit 88de9ad

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
@@ -55,6 +55,7 @@
5555
ServiceUnavailableError,
5656
TableAlreadyExistsError,
5757
UnauthorizedError,
58+
NoSuchIdentifierError,
5859
)
5960
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionSpec, assign_fresh_partition_spec_ids
6061
from pyiceberg.schema import Schema, assign_fresh_schema_ids
@@ -348,7 +349,7 @@ def _fetch_config(self) -> None:
348349
def _identifier_to_validated_tuple(self, identifier: Union[str, Identifier]) -> Identifier:
349350
identifier_tuple = self.identifier_to_tuple(identifier)
350351
if len(identifier_tuple) <= 1:
351-
raise NoSuchTableError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
352+
raise NoSuchIdentifierError(f"Missing namespace or invalid identifier: {'.'.join(identifier_tuple)}")
352353
return identifier_tuple
353354

354355
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
@@ -32,6 +32,7 @@
3232
NoSuchTableError,
3333
OAuthError,
3434
TableAlreadyExistsError,
35+
NoSuchIdentifierError,
3536
)
3637
from pyiceberg.io import load_file_io
3738
from pyiceberg.partitioning import PartitionField, PartitionSpec
@@ -1079,31 +1080,31 @@ def test_delete_table_404(rest_mock: Mocker) -> None:
10791080

10801081
def test_create_table_missing_namespace(rest_mock: Mocker, table_schema_simple: Schema) -> None:
10811082
table = "table"
1082-
with pytest.raises(NoSuchTableError) as e:
1083+
with pytest.raises(NoSuchIdentifierError) as e:
10831084
# Missing namespace
10841085
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).create_table(table, table_schema_simple)
10851086
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
10861087

10871088

10881089
def test_load_table_invalid_namespace(rest_mock: Mocker) -> None:
10891090
table = "table"
1090-
with pytest.raises(NoSuchTableError) as e:
1091+
with pytest.raises(NoSuchIdentifierError) as e:
10911092
# Missing namespace
10921093
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).load_table(table)
10931094
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
10941095

10951096

10961097
def test_drop_table_invalid_namespace(rest_mock: Mocker) -> None:
10971098
table = "table"
1098-
with pytest.raises(NoSuchTableError) as e:
1099+
with pytest.raises(NoSuchIdentifierError) as e:
10991100
# Missing namespace
11001101
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).drop_table(table)
11011102
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)
11021103

11031104

11041105
def test_purge_table_invalid_namespace(rest_mock: Mocker) -> None:
11051106
table = "table"
1106-
with pytest.raises(NoSuchTableError) as e:
1107+
with pytest.raises(NoSuchIdentifierError) as e:
11071108
# Missing namespace
11081109
RestCatalog("rest", uri=TEST_URI, token=TEST_TOKEN).purge_table(table)
11091110
assert f"Missing namespace or invalid identifier: {table}" in str(e.value)

0 commit comments

Comments
 (0)