Skip to content

Commit 554b691

Browse files
kevinjqliuCopilot
andcommitted
Fix BigQuery namespace miss handling
Report unsupported multipart namespace identifiers as NoSuchNamespaceError so CLI describe can continue to the table candidate without hiding unexpected catalog errors. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7ec1ef8 commit 554b691

2 files changed

Lines changed: 15 additions & 2 deletions

File tree

‎pyiceberg/catalog/bigquery_metastore.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def load_view(self, identifier: str | Identifier) -> View:
335335

336336
@override
337337
def load_namespace_properties(self, namespace: str | Identifier) -> Properties:
338-
dataset_name = self.identifier_to_database(namespace)
338+
dataset_name = self.identifier_to_database(namespace, NoSuchNamespaceError)
339339

340340
try:
341341
dataset = self.client.get_dataset(DatasetReference(project=self.project_id, dataset_id=dataset_name))

‎tests/catalog/test_bigquery_metastore.py‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,14 @@
1717
import os
1818
from unittest.mock import MagicMock
1919

20+
import pytest
2021
from google.api_core.exceptions import NotFound
2122
from google.cloud.bigquery import Dataset, DatasetReference, Table, TableReference
2223
from google.cloud.bigquery.external_config import ExternalCatalogDatasetOptions, ExternalCatalogTableOptions
2324
from pytest_mock import MockFixture
2425

2526
from pyiceberg.catalog.bigquery_metastore import ICEBERG_TABLE_TYPE_VALUE, TABLE_TYPE_PROP, BigQueryMetastoreCatalog
26-
from pyiceberg.exceptions import NoSuchTableError
27+
from pyiceberg.exceptions import NoSuchNamespaceError, NoSuchTableError
2728
from pyiceberg.schema import Schema
2829

2930

@@ -178,3 +179,15 @@ def test_list_namespaces(mocker: MockFixture) -> None:
178179
assert ("dataset1",) in namespaces
179180
assert ("dataset2",) in namespaces
180181
client_mock.list_datasets.assert_called_once()
182+
183+
184+
def test_load_namespace_properties_rejects_multipart_namespace(mocker: MockFixture) -> None:
185+
client_mock = MagicMock()
186+
mocker.patch("pyiceberg.catalog.bigquery_metastore.Client", return_value=client_mock)
187+
mocker.patch.dict(os.environ, values={"PYICEBERG_LEGACY_CURRENT_SNAPSHOT_ID": "True"})
188+
catalog = BigQueryMetastoreCatalog("test_catalog", **{"gcp.bigquery.project-id": "my-project"})
189+
190+
with pytest.raises(NoSuchNamespaceError, match="hierarchical namespaces are not supported"):
191+
catalog.load_namespace_properties(("dataset", "table"))
192+
193+
client_mock.get_dataset.assert_not_called()

0 commit comments

Comments
 (0)