diff --git a/bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreCatalog.java b/bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreCatalog.java index 0954aaae74e4..34ec7a62d5b5 100644 --- a/bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreCatalog.java +++ b/bigquery/src/main/java/org/apache/iceberg/gcp/bigquery/BigQueryMetastoreCatalog.java @@ -280,6 +280,16 @@ public Map loadNamespaceMetadata(Namespace namespace) { } } + @Override + protected boolean isValidIdentifier(TableIdentifier identifier) { + try { + validateNamespace(identifier.namespace()); + } catch (IllegalArgumentException e) { + return false; + } + return true; + } + @Override public String name() { return catalogName; diff --git a/bigquery/src/test/java/org/apache/iceberg/gcp/bigquery/TestBigQueryCatalog.java b/bigquery/src/test/java/org/apache/iceberg/gcp/bigquery/TestBigQueryCatalog.java index 4fa1bd29dad4..f7594f78ffac 100644 --- a/bigquery/src/test/java/org/apache/iceberg/gcp/bigquery/TestBigQueryCatalog.java +++ b/bigquery/src/test/java/org/apache/iceberg/gcp/bigquery/TestBigQueryCatalog.java @@ -21,6 +21,7 @@ import static org.apache.iceberg.CatalogUtil.ICEBERG_CATALOG_TYPE; import static org.apache.iceberg.CatalogUtil.ICEBERG_CATALOG_TYPE_BIGQUERY; import static org.apache.iceberg.gcp.bigquery.BigQueryMetastoreCatalog.PROJECT_ID; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.util.List; @@ -144,10 +145,6 @@ public void createTableTransaction(int formatVersion) { @Test public void testCreateTableWithDefaultColumnValue() {} - @Disabled("BigQuery Metastore does not support multi layer namespaces") - @Test - public void testLoadMetadataTable() {} - @Disabled("BigQuery Metastore does not support rename tables") @Test public void testRenameTable() { @@ -171,4 +168,31 @@ public void renameTableNamespaceMissing() { public void testRenameTableMissingSourceTable() { super.testRenameTableMissingSourceTable(); } + + @Test + public void testIsValidIdentifierWithValidSingleLevelNamespace() { + assertThat(catalog.isValidIdentifier(TableIdentifier.of("dataset1", "table1"))).isTrue(); + } + + @Test + public void testIsValidIdentifierWithInvalidMultiLevelNamespace() { + assertThat( + catalog.isValidIdentifier( + TableIdentifier.of(Namespace.of("level1", "level2"), "table1"))) + .isFalse(); + } + + @Test + public void testIsValidIdentifierWithThreeLevelNamespace() { + assertThat( + catalog.isValidIdentifier( + TableIdentifier.of(Namespace.of("level1", "level2", "level3"), "table1"))) + .isFalse(); + } + + @Test + public void testIsValidIdentifierWithEmptyNamespace() { + assertThat(catalog.isValidIdentifier(TableIdentifier.of(Namespace.empty(), "table1"))) + .isFalse(); + } }