Search in sources :

Example 1 with Content

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

the class TestNessieIcebergViews method verifyViewInNessie.

private void verifyViewInNessie(TableIdentifier viewIdentifier, View icebergView) throws NessieNotFoundException {
    ContentKey contentKey = ContentKey.of(viewIdentifier.toString().split("\\."));
    Map<ContentKey, Content> contentMap = api.getContent().key(contentKey).refName(BRANCH).get();
    assertThat(contentMap).hasSize(1).containsKey(contentKey);
    Content content = contentMap.get(contentKey);
    assertThat(content.unwrap(IcebergView.class)).isPresent();
    IcebergView view = content.unwrap(IcebergView.class).get();
    assertThat(metadataFilesForViewsPath(viewIdentifier.name())).contains(view.getMetadataLocation());
    // TODO: currently the schema id is always 0
    assertThat(view.getSchemaId()).isEqualTo(icebergView.currentVersion().viewDefinition().schema().schemaId());
    assertThat(view.getVersionId()).isEqualTo(view.getVersionId());
    assertThat(view.getSqlText()).isEqualTo(icebergView.currentVersion().viewDefinition().sql());
// TODO: currently not implemented in the view definition
// assertThat(view.getDialect()).isEqualTo(viewDefinition.dialect());
}
Also used : ContentKey(org.projectnessie.model.ContentKey) Content(org.projectnessie.model.Content) IcebergView(org.projectnessie.model.IcebergView)

Example 2 with Content

use of org.projectnessie.model.Content 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 Content

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

the class TableCommitMetaStoreWorker method toStoreOnReferenceState.

@Override
public ByteString toStoreOnReferenceState(Content content) {
    ObjectTypes.Content.Builder builder = ObjectTypes.Content.newBuilder().setId(content.getId());
    if (content instanceof IcebergTable) {
        IcebergTable state = (IcebergTable) content;
        ObjectTypes.IcebergRefState.Builder stateBuilder = ObjectTypes.IcebergRefState.newBuilder().setSnapshotId(state.getSnapshotId()).setSchemaId(state.getSchemaId()).setSpecId(state.getSpecId()).setSortOrderId(state.getSortOrderId());
        builder.setIcebergRefState(stateBuilder);
    } else if (content instanceof IcebergView) {
        IcebergView view = (IcebergView) content;
        builder.setIcebergViewState(ObjectTypes.IcebergViewState.newBuilder().setVersionId(view.getVersionId()).setSchemaId(view.getSchemaId()).setDialect(view.getDialect()).setSqlText(view.getSqlText()));
    } else if (content instanceof DeltaLakeTable) {
        ObjectTypes.DeltaLakeTable.Builder table = ObjectTypes.DeltaLakeTable.newBuilder().addAllMetadataLocationHistory(((DeltaLakeTable) content).getMetadataLocationHistory()).addAllCheckpointLocationHistory(((DeltaLakeTable) content).getCheckpointLocationHistory());
        String lastCheckpoint = ((DeltaLakeTable) content).getLastCheckpoint();
        if (lastCheckpoint != null) {
            table.setLastCheckpoint(lastCheckpoint);
        }
        builder.setDeltaLakeTable(table);
    } else if (content instanceof Namespace) {
        builder.setNamespace(ObjectTypes.Namespace.newBuilder().setName(((Namespace) content).name()));
    } else {
        throw new IllegalArgumentException("Unknown type " + content);
    }
    return builder.build().toByteString();
}
Also used : ImmutableDeltaLakeTable(org.projectnessie.model.ImmutableDeltaLakeTable) DeltaLakeTable(org.projectnessie.model.DeltaLakeTable) Content(org.projectnessie.model.Content) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ByteString(com.google.protobuf.ByteString) ImmutableNamespace(org.projectnessie.model.ImmutableNamespace) Namespace(org.projectnessie.model.Namespace)

Example 4 with Content

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

the class TestStoreWorker method testSerdeIcebergView.

@Test
void testSerdeIcebergView() {
    String path = "foo/view";
    String dialect = "Dremio";
    String sqlText = "select * from world";
    IcebergView view = IcebergView.of(ID, path, 1, 123, dialect, sqlText);
    ObjectTypes.Content protoTableGlobal = ObjectTypes.Content.newBuilder().setId(ID).setIcebergMetadataPointer(IcebergMetadataPointer.newBuilder().setMetadataLocation(path)).build();
    ObjectTypes.Content protoOnRef = ObjectTypes.Content.newBuilder().setId(ID).setIcebergViewState(IcebergViewState.newBuilder().setVersionId(1).setDialect(dialect).setSchemaId(123).setSqlText(sqlText)).build();
    ByteString tableGlobalBytes = worker.toStoreGlobalState(view);
    ByteString snapshotBytes = worker.toStoreOnReferenceState(view);
    Assertions.assertEquals(protoTableGlobal.toByteString(), tableGlobalBytes);
    Assertions.assertEquals(protoOnRef.toByteString(), snapshotBytes);
    Content deserialized = worker.valueFromStore(snapshotBytes, Optional.of(tableGlobalBytes));
    Assertions.assertEquals(view, deserialized);
}
Also used : ByteString(com.google.protobuf.ByteString) Content(org.projectnessie.model.Content) IcebergView(org.projectnessie.model.IcebergView) ObjectTypes(org.projectnessie.store.ObjectTypes) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Content

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

the class TestStoreWorker method testSerdeIceberg.

@Test
void testSerdeIceberg() {
    String path = "foo/bar";
    IcebergTable table = IcebergTable.of(path, 42, 43, 44, 45, ID);
    ObjectTypes.Content protoTableGlobal = ObjectTypes.Content.newBuilder().setId(ID).setIcebergMetadataPointer(IcebergMetadataPointer.newBuilder().setMetadataLocation(path)).build();
    ObjectTypes.Content protoOnRef = ObjectTypes.Content.newBuilder().setId(ID).setIcebergRefState(IcebergRefState.newBuilder().setSnapshotId(42).setSchemaId(43).setSpecId(44).setSortOrderId(45)).build();
    ByteString tableGlobalBytes = worker.toStoreGlobalState(table);
    ByteString snapshotBytes = worker.toStoreOnReferenceState(table);
    Assertions.assertEquals(protoTableGlobal.toByteString(), tableGlobalBytes);
    Assertions.assertEquals(protoOnRef.toByteString(), snapshotBytes);
    Content deserialized = worker.valueFromStore(snapshotBytes, Optional.of(tableGlobalBytes));
    Assertions.assertEquals(table, deserialized);
}
Also used : ByteString(com.google.protobuf.ByteString) Content(org.projectnessie.model.Content) IcebergTable(org.projectnessie.model.IcebergTable) ObjectTypes(org.projectnessie.store.ObjectTypes) ByteString(com.google.protobuf.ByteString) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

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