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());
}
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));
}
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();
}
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);
}
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);
}
Aggregations