Search in sources :

Example 1 with Builder

use of org.projectnessie.model.ImmutableDeltaLakeTable.Builder in project nessie by projectnessie.

the class TableCommitMetaStoreWorker method toStoreGlobalState.

@Override
public ByteString toStoreGlobalState(Content content) {
    ObjectTypes.Content.Builder builder = ObjectTypes.Content.newBuilder().setId(content.getId());
    if (content instanceof IcebergTable) {
        IcebergTable state = (IcebergTable) content;
        ObjectTypes.IcebergMetadataPointer.Builder stateBuilder = ObjectTypes.IcebergMetadataPointer.newBuilder().setMetadataLocation(state.getMetadataLocation());
        builder.setIcebergMetadataPointer(stateBuilder);
    } else if (content instanceof IcebergView) {
        IcebergView state = (IcebergView) content;
        ObjectTypes.IcebergMetadataPointer.Builder stateBuilder = ObjectTypes.IcebergMetadataPointer.newBuilder().setMetadataLocation(state.getMetadataLocation());
        builder.setIcebergMetadataPointer(stateBuilder);
    } else {
        throw new IllegalArgumentException("Unknown type " + content);
    }
    return builder.build().toByteString();
}
Also used : Content(org.projectnessie.model.Content) Builder(org.projectnessie.model.ImmutableDeltaLakeTable.Builder) ImmutableIcebergTable(org.projectnessie.model.ImmutableIcebergTable) IcebergTable(org.projectnessie.model.IcebergTable) ImmutableIcebergView(org.projectnessie.model.ImmutableIcebergView) IcebergView(org.projectnessie.model.IcebergView) ObjectTypes(org.projectnessie.store.ObjectTypes)

Example 2 with Builder

use of org.projectnessie.model.ImmutableDeltaLakeTable.Builder in project nessie by projectnessie.

the class TableCommitMetaStoreWorker method valueFromStore.

@Override
public Content valueFromStore(ByteString onReferenceValue, Optional<ByteString> globalState) {
    ObjectTypes.Content content = parse(onReferenceValue);
    Optional<ObjectTypes.Content> globalContent = globalState.map(TableCommitMetaStoreWorker::parse);
    switch(content.getObjectTypeCase()) {
        case DELTA_LAKE_TABLE:
            Builder builder = ImmutableDeltaLakeTable.builder().id(content.getId()).addAllMetadataLocationHistory(content.getDeltaLakeTable().getMetadataLocationHistoryList()).addAllCheckpointLocationHistory(content.getDeltaLakeTable().getCheckpointLocationHistoryList());
            if (content.getDeltaLakeTable().getLastCheckpoint() != null) {
                builder.lastCheckpoint(content.getDeltaLakeTable().getLastCheckpoint());
            }
            return builder.build();
        case ICEBERG_REF_STATE:
            ObjectTypes.Content global = globalContent.orElseThrow(TableCommitMetaStoreWorker::noIcebergMetadataPointer);
            if (!global.hasIcebergMetadataPointer()) {
                throw noIcebergMetadataPointer();
            }
            return ImmutableIcebergTable.builder().metadataLocation(global.getIcebergMetadataPointer().getMetadataLocation()).snapshotId(content.getIcebergRefState().getSnapshotId()).schemaId(content.getIcebergRefState().getSchemaId()).specId(content.getIcebergRefState().getSpecId()).sortOrderId(content.getIcebergRefState().getSortOrderId()).id(content.getId()).build();
        case ICEBERG_VIEW_STATE:
            ObjectTypes.Content globalView = globalContent.orElseThrow(TableCommitMetaStoreWorker::noIcebergMetadataPointer);
            if (!globalView.hasIcebergMetadataPointer()) {
                throw noIcebergMetadataPointer();
            }
            ObjectTypes.IcebergViewState view = content.getIcebergViewState();
            return ImmutableIcebergView.builder().metadataLocation(globalView.getIcebergMetadataPointer().getMetadataLocation()).versionId(view.getVersionId()).schemaId(view.getSchemaId()).dialect(view.getDialect()).sqlText(view.getSqlText()).id(content.getId()).build();
        case NAMESPACE:
            ObjectTypes.Namespace namespace = content.getNamespace();
            return ImmutableNamespace.builder().id(content.getId()).name(namespace.getName()).build();
        case OBJECTTYPE_NOT_SET:
        default:
            throw new IllegalArgumentException("Unknown type " + content.getObjectTypeCase());
    }
}
Also used : Content(org.projectnessie.model.Content) Builder(org.projectnessie.model.ImmutableDeltaLakeTable.Builder) ObjectTypes(org.projectnessie.store.ObjectTypes)

Aggregations

Content (org.projectnessie.model.Content)2 Builder (org.projectnessie.model.ImmutableDeltaLakeTable.Builder)2 ObjectTypes (org.projectnessie.store.ObjectTypes)2 IcebergTable (org.projectnessie.model.IcebergTable)1 IcebergView (org.projectnessie.model.IcebergView)1 ImmutableIcebergTable (org.projectnessie.model.ImmutableIcebergTable)1 ImmutableIcebergView (org.projectnessie.model.ImmutableIcebergView)1