Search in sources :

Example 81 with Branch

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

the class NessieViewOperations method commit.

@Override
public void commit(ViewVersionMetadata base, ViewVersionMetadata metadata, Map<String, String> properties) {
    reference.checkMutable();
    String newMetadataLocation = writeNewMetadata(metadata, currentVersion() + 1);
    boolean delete = true;
    try {
        ImmutableIcebergView.Builder viewBuilder = ImmutableIcebergView.builder();
        if (icebergView != null) {
            viewBuilder.id(icebergView.getId());
        }
        IcebergView newView = viewBuilder.metadataLocation(newMetadataLocation).versionId(metadata.currentVersionId()).schemaId(metadata.definition().schema().schemaId()).dialect("TODO: needs to be defined in Iceberg ViewDefinition").sqlText(metadata.definition().sql()).build();
        LOG.debug("Committing '{}' against '{}': {}", key, reference.getReference(), newView);
        ImmutableCommitMeta.Builder builder = ImmutableCommitMeta.builder();
        builder.message(buildCommitMsg(base, metadata) + " " + key.getName());
        Branch branch = api.commitMultipleOperations().operation(Operation.Put.of(key, newView, icebergView)).commitMeta(NessieUtil.catalogOptions(builder, catalogOptions).build()).branch(reference.getAsBranch()).commit();
        reference.updateReference(branch);
        delete = false;
    } catch (NessieConflictException ex) {
        throw new CommitFailedException(ex, "Commit failed: Reference hash is out of date. " + "Update the reference %s and try again", reference.getName());
    } catch (HttpClientException ex) {
        // Intentionally catch all nessie-client-exceptions here and not just the "timeout" variant
        // to catch all kinds of network errors (e.g. connection reset). Network code implementation
        // details and all kinds of network devices can induce unexpected behavior. So better be
        // safe than sorry.
        delete = false;
        throw new CommitStateUnknownException(ex);
    } catch (NessieNotFoundException ex) {
        throw new RuntimeException(String.format("Commit failed: Reference %s no longer exist", reference.getName()), ex);
    } finally {
        if (delete) {
            io().deleteFile(newMetadataLocation);
        }
    }
}
Also used : ImmutableCommitMeta(org.projectnessie.model.ImmutableCommitMeta) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) CommitStateUnknownException(org.apache.iceberg.exceptions.CommitStateUnknownException) NessieNotFoundException(org.projectnessie.error.NessieNotFoundException) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) HttpClientException(org.projectnessie.client.http.HttpClientException) Branch(org.projectnessie.model.Branch) NessieConflictException(org.projectnessie.error.NessieConflictException) CommitFailedException(org.apache.iceberg.exceptions.CommitFailedException)

Aggregations

Branch (org.projectnessie.model.Branch)81 Test (org.junit.jupiter.api.Test)56 IcebergTable (org.projectnessie.model.IcebergTable)30 ContentKey (org.projectnessie.model.ContentKey)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 LogResponse (org.projectnessie.model.LogResponse)19 Reference (org.projectnessie.model.Reference)19 CommitMeta (org.projectnessie.model.CommitMeta)18 Instant (java.time.Instant)16 LogEntry (org.projectnessie.model.LogResponse.LogEntry)13 List (java.util.List)12 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)12 Tag (org.projectnessie.model.Tag)12 Collectors (java.util.stream.Collectors)11 NessieNotFoundException (org.projectnessie.error.NessieNotFoundException)11 Content (org.projectnessie.model.Content)11 Entry (org.projectnessie.model.EntriesResponse.Entry)10 Put (org.projectnessie.model.Operation.Put)10 IcebergView (org.projectnessie.model.IcebergView)9 Map (java.util.Map)8