use of io.deephaven.web.client.api.subscription.ViewportData.NO_ROW_FORMAT_COLUMN in project deephaven-core by deephaven.
the class TableViewportSubscription method snapshot.
@JsMethod
public Promise<TableData> snapshot(JsRangeSet rows, Column[] columns) {
// TODO #1039 slice rows and drop columns
return copy.then(table -> {
final ClientTableState state = table.state();
String[] columnTypes = Arrays.stream(state.getTableDef().getColumns()).map(ColumnDefinition::getType).toArray(String[]::new);
final BitSet columnBitset = table.lastVisibleState().makeBitset(columns);
return Callbacks.<TableSnapshot, String>promise(this, callback -> {
WorkerConnection connection = table.getConnection();
BiDiStream<FlightData, FlightData> stream = connection.<FlightData, FlightData>streamFactory().create(headers -> connection.flightServiceClient().doExchange(headers), (first, headers) -> connection.browserFlightServiceClient().openDoExchange(first, headers), (next, headers, c) -> connection.browserFlightServiceClient().nextDoExchange(next, headers, c::apply), new FlightData());
Builder doGetRequest = new Builder(1024);
double columnsOffset = BarrageSubscriptionRequest.createColumnsVector(doGetRequest, makeUint8ArrayFromBitset(columnBitset));
double viewportOffset = BarrageSubscriptionRequest.createViewportVector(doGetRequest, serializeRanges(Collections.singleton(rows.getRange())));
double serializationOptionsOffset = BarrageSnapshotOptions.createBarrageSnapshotOptions(doGetRequest, ColumnConversionMode.Stringify, true, 0);
double tableTicketOffset = BarrageSubscriptionRequest.createTicketVector(doGetRequest, state.getHandle().getTicket());
BarrageSnapshotRequest.startBarrageSnapshotRequest(doGetRequest);
BarrageSnapshotRequest.addTicket(doGetRequest, tableTicketOffset);
BarrageSnapshotRequest.addColumns(doGetRequest, columnsOffset);
BarrageSnapshotRequest.addSnapshotOptions(doGetRequest, serializationOptionsOffset);
BarrageSnapshotRequest.addViewport(doGetRequest, viewportOffset);
doGetRequest.finish(BarrageSnapshotRequest.endBarrageSnapshotRequest(doGetRequest));
FlightData request = new FlightData();
request.setAppMetadata(BarrageUtils.wrapMessage(doGetRequest, BarrageMessageType.BarrageSnapshotRequest));
stream.send(request);
stream.end();
stream.onData(flightData -> {
Message message = Message.getRootAsMessage(new ByteBuffer(flightData.getDataHeader_asU8()));
if (message.headerType() == MessageHeader.Schema) {
// ignore for now, we'll handle this later
return;
}
assert message.headerType() == MessageHeader.RecordBatch;
RecordBatch header = message.header(new RecordBatch());
Uint8Array appMetadataBytes = flightData.getAppMetadata_asU8();
BarrageUpdateMetadata update = null;
if (appMetadataBytes.length != 0) {
BarrageMessageWrapper barrageMessageWrapper = BarrageMessageWrapper.getRootAsBarrageMessageWrapper(new io.deephaven.javascript.proto.dhinternal.flatbuffers.ByteBuffer(appMetadataBytes));
update = BarrageUpdateMetadata.getRootAsBarrageUpdateMetadata(new ByteBuffer(new Uint8Array(barrageMessageWrapper.msgPayloadArray())));
}
TableSnapshot snapshot = BarrageUtils.createSnapshot(header, BarrageUtils.typedArrayToLittleEndianByteBuffer(flightData.getDataBody_asU8()), update, true, columnTypes);
callback.onSuccess(snapshot);
});
stream.onStatus(status -> {
if (!status.isOk()) {
callback.onFailure(status.getDetails());
}
});
}).then(defer()).then(snapshot -> {
SubscriptionTableData pretendSubscription = new SubscriptionTableData(Js.uncheckedCast(columns), state.getRowFormatColumn() == null ? NO_ROW_FORMAT_COLUMN : state.getRowFormatColumn().getIndex(), null);
TableData data = pretendSubscription.handleSnapshot(snapshot);
return Promise.resolve(data);
}).then(defer());
});
}
Aggregations