Search in sources :

Example 1 with CommitMeta

use of org.projectnessie.model.CommitMeta in project iceberg by apache.

the class NessieUtilTest method testAuthorIsNullWithoutJvmUser.

@Test
public void testAuthorIsNullWithoutJvmUser() {
    String jvmUserName = System.getProperty("user.name");
    try {
        System.clearProperty("user.name");
        CommitMeta commitMeta = NessieUtil.buildCommitMetadata("commit msg", ImmutableMap.of());
        Assertions.assertThat(commitMeta.getAuthor()).isNull();
    } finally {
        System.setProperty("user.name", jvmUserName);
    }
}
Also used : CommitMeta(org.projectnessie.model.CommitMeta) Test(org.junit.jupiter.api.Test)

Example 2 with CommitMeta

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

the class PersistVersionStoreExtension method afterBeanDiscovery.

@SuppressWarnings("unused")
public void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) {
    TableCommitMetaStoreWorker storeWorker = new TableCommitMetaStoreWorker();
    abd.addBean().addType(new TypeLiteral<VersionStore<Content, CommitMeta, Type>>() {
    }).addQualifier(Default.Literal.INSTANCE).scope(ApplicationScoped.class).produceWith(i -> new PersistVersionStore<>(databaseAdapter.get(), storeWorker));
}
Also used : Type(org.projectnessie.model.Content.Type) TypeLiteral(javax.enterprise.util.TypeLiteral) TableCommitMetaStoreWorker(org.projectnessie.server.store.TableCommitMetaStoreWorker) Content(org.projectnessie.model.Content) CommitMeta(org.projectnessie.model.CommitMeta) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 3 with CommitMeta

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

the class AbstractSparkSqlTest method commitAndReturnLog.

private List<Object[]> commitAndReturnLog(String branch) throws NessieConflictException, NessieNotFoundException {
    assertThat(sql("CREATE BRANCH %s IN nessie", branch)).containsExactly(row("Branch", branch, hash));
    ContentKey key = ContentKey.of("table", "name");
    CommitMeta cm1 = ImmutableCommitMeta.builder().author("sue").authorTime(Instant.ofEpochMilli(1)).message("1").putProperties("test", "123").build();
    CommitMeta cm2 = ImmutableCommitMeta.builder().author("janet").authorTime(Instant.ofEpochMilli(10)).message("2").putProperties("test", "123").build();
    CommitMeta cm3 = ImmutableCommitMeta.builder().author("alice").authorTime(Instant.ofEpochMilli(100)).message("3").putProperties("test", "123").build();
    Operations ops = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("foo", 42, 42, 42, 42))).commitMeta(cm1).build();
    Operations ops2 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("bar", 42, 42, 42, 42))).commitMeta(cm2).build();
    Operations ops3 = ImmutableOperations.builder().addOperations(Operation.Put.of(key, IcebergTable.of("baz", 42, 42, 42, 42))).commitMeta(cm3).build();
    Branch ref1 = api.commitMultipleOperations().branchName(branch).hash(hash).operations(ops.getOperations()).commitMeta(ops.getCommitMeta()).commit();
    Branch ref2 = api.commitMultipleOperations().branchName(branch).hash(ref1.getHash()).operations(ops2.getOperations()).commitMeta(ops2.getCommitMeta()).commit();
    Branch ref3 = api.commitMultipleOperations().branchName(branch).hash(ref2.getHash()).operations(ops3.getOperations()).commitMeta(ops3.getCommitMeta()).commit();
    List<Object[]> resultList = new ArrayList<>();
    resultList.add(cmToRow(cm3, ref3.getHash()));
    resultList.add(cmToRow(cm2, ref2.getHash()));
    resultList.add(cmToRow(cm1, ref1.getHash()));
    return resultList;
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Branch(org.projectnessie.model.Branch) ArrayList(java.util.ArrayList) ImmutableCommitMeta(org.projectnessie.model.ImmutableCommitMeta) CommitMeta(org.projectnessie.model.CommitMeta) ImmutableOperations(org.projectnessie.model.ImmutableOperations) Operations(org.projectnessie.model.Operations)

Example 4 with CommitMeta

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

the class TreeApiImpl method filterReferences.

/**
 * Applies different filters to the {@link Stream} of references on the filter.
 *
 * @param references The references that different filters will be applied to
 * @param filter The filter to filter by
 * @return A potentially filtered {@link Stream} of commits based on the filter
 */
private Stream<Reference> filterReferences(Stream<Reference> references, String filter) {
    if (Strings.isNullOrEmpty(filter)) {
        return references;
    }
    final Script script;
    try {
        script = SCRIPT_HOST.buildScript(filter).withContainer(CONTAINER).withDeclarations(REFERENCES_DECLARATIONS).withTypes(REFERENCES_TYPES).build();
    } catch (ScriptException e) {
        throw new IllegalArgumentException(e);
    }
    return references.filter(reference -> {
        try {
            ReferenceMetadata refMeta = reference.getMetadata();
            if (refMeta == null) {
                refMeta = CELUtil.EMPTY_REFERENCE_METADATA;
            }
            CommitMeta commit = refMeta.getCommitMetaOfHEAD();
            if (commit == null) {
                commit = CELUtil.EMPTY_COMMIT_META;
            }
            return script.execute(Boolean.class, ImmutableMap.of(VAR_REF, reference, VAR_REF_TYPE, reference.getType().name(), VAR_COMMIT, commit, VAR_REF_META, refMeta));
        } catch (ScriptException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : Script(org.projectnessie.cel.tools.Script) ScriptException(org.projectnessie.cel.tools.ScriptException) CommitMeta(org.projectnessie.model.CommitMeta) ReferenceMetadata(org.projectnessie.model.ReferenceMetadata) ImmutableReferenceMetadata(org.projectnessie.model.ImmutableReferenceMetadata)

Example 5 with CommitMeta

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

the class TreeApiImpl method assignReference.

protected void assignReference(NamedRef ref, String oldHash, Reference assignTo) throws NessieNotFoundException, NessieConflictException {
    try {
        ReferenceInfo<CommitMeta> resolved = getStore().getNamedRef(ref.getName(), GetNamedRefsParams.DEFAULT);
        getStore().assign(resolved.getNamedRef(), toHash(oldHash, true), toHash(assignTo.getName(), assignTo.getHash()));
    } catch (ReferenceNotFoundException e) {
        throw new NessieReferenceNotFoundException(e.getMessage(), e);
    } catch (ReferenceConflictException e) {
        throw new NessieReferenceConflictException(e.getMessage(), e);
    }
}
Also used : NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceNotFoundException(org.projectnessie.versioned.ReferenceNotFoundException) NessieReferenceNotFoundException(org.projectnessie.error.NessieReferenceNotFoundException) ReferenceConflictException(org.projectnessie.versioned.ReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) NessieReferenceConflictException(org.projectnessie.error.NessieReferenceConflictException) CommitMeta(org.projectnessie.model.CommitMeta)

Aggregations

CommitMeta (org.projectnessie.model.CommitMeta)37 Branch (org.projectnessie.model.Branch)17 LogEntry (org.projectnessie.model.LogResponse.LogEntry)15 Test (org.junit.jupiter.api.Test)14 IcebergTable (org.projectnessie.model.IcebergTable)14 ContentKey (org.projectnessie.model.ContentKey)13 LogResponse (org.projectnessie.model.LogResponse)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Content (org.projectnessie.model.Content)10 List (java.util.List)9 Collectors (java.util.stream.Collectors)9 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)8 BaseNessieClientServerException (org.projectnessie.error.BaseNessieClientServerException)8 NessieReferenceNotFoundException (org.projectnessie.error.NessieReferenceNotFoundException)8 Reference (org.projectnessie.model.Reference)7 ArrayList (java.util.ArrayList)6 Entry (org.projectnessie.model.EntriesResponse.Entry)6 Operation (org.projectnessie.model.Operation)6 Put (org.projectnessie.model.Operation.Put)6 Stream (java.util.stream.Stream)5