Skip to content

Commit

Permalink
Nessie: Support views for NessieCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ajantha-bhat committed Oct 23, 2023
1 parent e2b56da commit 66ea0be
Show file tree
Hide file tree
Showing 7 changed files with 725 additions and 102 deletions.
22 changes: 18 additions & 4 deletions core/src/test/java/org/apache/iceberg/view/ViewCatalogTests.java
Expand Up @@ -400,8 +400,15 @@ public void replaceTableViaTransactionThatAlreadyExistsAsView() {
.buildTable(viewIdentifier, SCHEMA)
.replaceTransaction()
.commitTransaction())
.isInstanceOf(NoSuchTableException.class)
.hasMessageStartingWith("Table does not exist: ns.view");
.satisfiesAnyOf(
throwable ->
assertThat(throwable)
.isInstanceOf(NoSuchTableException.class)
.hasMessageStartingWith("Table does not exist: ns.view"),
throwable ->
assertThat(throwable)
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("View with same name already exists: ns.view"));
}

@Test
Expand Down Expand Up @@ -465,8 +472,15 @@ public void replaceViewThatAlreadyExistsAsTable() {
.withDefaultNamespace(tableIdentifier.namespace())
.withQuery("spark", "select * from ns.tbl")
.replace())
.isInstanceOf(NoSuchViewException.class)
.hasMessageStartingWith("View does not exist: ns.table");
.satisfiesAnyOf(
throwable ->
assertThat(throwable)
.isInstanceOf(NoSuchViewException.class)
.hasMessageStartingWith("View does not exist: ns.table"),
throwable ->
assertThat(throwable)
.isInstanceOf(AlreadyExistsException.class)
.hasMessageContaining("Table with same name already exists: ns.table"));
}

@Test
Expand Down
31 changes: 29 additions & 2 deletions nessie/src/main/java/org/apache/iceberg/nessie/NessieCatalog.java
Expand Up @@ -24,7 +24,6 @@
import java.util.Set;
import java.util.UUID;
import java.util.function.Function;
import org.apache.iceberg.BaseMetastoreCatalog;
import org.apache.iceberg.CatalogProperties;
import org.apache.iceberg.CatalogUtil;
import org.apache.iceberg.TableOperations;
Expand All @@ -41,6 +40,8 @@
import org.apache.iceberg.relocated.com.google.common.base.Joiner;
import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
import org.apache.iceberg.view.BaseMetastoreViewCatalog;
import org.apache.iceberg.view.ViewOperations;
import org.projectnessie.client.NessieClientBuilder;
import org.projectnessie.client.NessieConfigConstants;
import org.projectnessie.client.api.NessieApiV1;
Expand All @@ -53,7 +54,7 @@
import org.slf4j.LoggerFactory;

/** Nessie implementation of Iceberg Catalog. */
public class NessieCatalog extends BaseMetastoreCatalog
public class NessieCatalog extends BaseMetastoreViewCatalog
implements AutoCloseable, SupportsNamespaces, Configurable<Object> {

private static final Logger LOG = LoggerFactory.getLogger(NessieCatalog.class);
Expand Down Expand Up @@ -347,4 +348,30 @@ private TableIdentifier identifierWithoutTableReference(
protected Map<String, String> properties() {
return catalogOptions;
}

@Override
protected ViewOperations newViewOps(TableIdentifier identifier) {
TableReference tr = parseTableReference(identifier);
return new NessieViewOperations(
ContentKey.of(
org.projectnessie.model.Namespace.of(identifier.namespace().levels()), tr.getName()),
client.withReference(tr.getReference(), tr.getHash()),
fileIO,
catalogOptions);
}

@Override
public List<TableIdentifier> listViews(Namespace namespace) {
return client.listViews(namespace);
}

@Override
public boolean dropView(TableIdentifier identifier) {
return client.dropView(identifier, false);
}

@Override
public void renameView(TableIdentifier from, TableIdentifier to) {
client.renameView(from, to);
}
}

0 comments on commit 66ea0be

Please sign in to comment.