Search in sources :

Example 31 with Content

use of org.projectnessie.model.Content in project nessie by projectnessie.

the class NessieViewOperations method refresh.

@Override
public ViewVersionMetadata refresh() {
    try {
        reference.refresh(api);
    } catch (NessieNotFoundException e) {
        throw new RuntimeException("Failed to refresh as ref is no longer valid.", e);
    }
    String metadataLocation = null;
    try {
        Content content = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        LOG.debug("Content '{}' at '{}': {}", key, reference.getReference(), content);
        if (content == null) {
            if (currentMetadataLocation() != null) {
                throw new NoSuchTableException("No such view %s in %s", key, reference.getReference());
            }
        } else {
            this.icebergView = content.unwrap(IcebergView.class).orElseThrow(() -> new IllegalStateException("Cannot refresh iceberg view: " + String.format("Nessie points to a non-Iceberg object for path: %s.", key)));
            metadataLocation = icebergView.getMetadataLocation();
        }
    } catch (NessieNotFoundException ex) {
        if (currentMetadataLocation() != null) {
            throw new NoSuchTableException(ex, "No such view %s", key);
        }
    }
    refreshFromMetadataLocation(metadataLocation, RETRY_IF, 2);
    return current();
}
Also used : Content(org.projectnessie.model.Content) NoSuchTableException(org.apache.iceberg.exceptions.NoSuchTableException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Example 32 with Content

use of org.projectnessie.model.Content in project nessie by projectnessie.

the class NessieViewOperations method view.

private IcebergView view(TableIdentifier viewIdentifier) {
    try {
        ContentKey key = NessieUtil.toKey(viewIdentifier);
        Content view = api.getContent().key(key).reference(reference.getReference()).get().get(key);
        return view != null ? view.unwrap(IcebergView.class).orElse(null) : null;
    } catch (NessieNotFoundException e) {
        return null;
    }
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Content(org.projectnessie.model.Content) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException)

Aggregations

Content (org.projectnessie.model.Content)32 ContentKey (org.projectnessie.model.ContentKey)16 CommitMeta (org.projectnessie.model.CommitMeta)11 IcebergTable (org.projectnessie.model.IcebergTable)11 Test (org.junit.jupiter.api.Test)9 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)9 Branch (org.projectnessie.model.Branch)8 Map (java.util.Map)7 ByteString (com.google.protobuf.ByteString)6 IcebergView (org.projectnessie.model.IcebergView)6 HashMap (java.util.HashMap)5 List (java.util.List)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NessieApiV1 (org.projectnessie.client.api.NessieApiV1)5 Reference (org.projectnessie.model.Reference)5 Instant (java.time.Instant)4 ArrayList (java.util.ArrayList)4 LogResponse (org.projectnessie.model.LogResponse)4 Put (org.projectnessie.model.Operation.Put)4 HashSet (java.util.HashSet)3