Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,8 @@ public boolean setProperties(Namespace namespace, Map<String, String> properties

@Override
public boolean removeProperties(Namespace namespace, Set<String> properties) {
if (!namespaceExists(namespace)) {
throw new NoSuchNamespaceException("Namespace does not exist: %s", namespace);
}

Preconditions.checkNotNull(properties, "Invalid properties to remove: null");

if (properties.isEmpty()) {
return false;
}

return client.removeParameters(toDatasetReference(namespace), properties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,17 @@
import static org.apache.iceberg.CatalogUtil.ICEBERG_CATALOG_TYPE_BIGQUERY;
import static org.apache.iceberg.gcp.bigquery.BigQueryProperties.PROJECT_ID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.google.api.services.bigquery.model.DatasetReference;
import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.catalog.CatalogTests;
import org.apache.iceberg.catalog.Namespace;
Expand All @@ -45,6 +51,7 @@
public class TestBigQueryCatalog extends CatalogTests<BigQueryMetastoreCatalog> {
@TempDir private File tempFolder;
private BigQueryMetastoreCatalog catalog;
private FakeBigQueryMetastoreClient client;

@BeforeEach
public void before() throws Exception {
Expand Down Expand Up @@ -99,7 +106,7 @@ protected BigQueryMetastoreCatalog initCatalog(
String catalogName, Map<String, String> additionalProperties) {

String warehouseLocation = tempFolder.toPath().resolve("hive-warehouse").toString();
FakeBigQueryMetastoreClient fakeBigQueryClient = new FakeBigQueryMetastoreClient();
this.client = spy(new FakeBigQueryMetastoreClient());

Map<String, String> properties =
Map.of(
Expand Down Expand Up @@ -129,7 +136,7 @@ protected BigQueryMetastoreCatalog initCatalog(
.build(),
"project-id",
"us-central1",
fakeBigQueryClient);
client);

return tmpCatalog;
}
Expand Down Expand Up @@ -208,4 +215,16 @@ public void testIsValidIdentifierWithEmptyNamespace() {
assertThat(catalog.isValidIdentifier(TableIdentifier.of(Namespace.empty(), "table1")))
.isFalse();
}

@Test
public void removePropertiesLoadsNamespaceOnce() {
Namespace namespace = Namespace.of("namespace");
catalog.createNamespace(namespace, ImmutableMap.of("key", "value"));
clearInvocations(client);

assertThat(catalog.removeProperties(namespace, Set.of("key"))).isTrue();

verify(client, times(1))
.load(new DatasetReference().setProjectId("project-id").setDatasetId("namespace"));
}
}
Loading