use of io.deephaven.web.shared.data.columns.ColumnData in project deephaven-core by deephaven.
the class SubscriptionTableData method handleSnapshot.
// TODO support this being called multiple times so we can keep viewports going without clearing the data
public TableData handleSnapshot(TableSnapshot snapshot) {
// when changing snapshots we should actually rewrite the columns, possibly emulate ViewportData more?
ColumnData[] dataColumns = snapshot.getDataColumns();
data = new Object[dataColumns.length];
reusableDestinations = RangeSet.empty();
redirectedIndexes = new TreeMap<>();
index = snapshot.getIncludedRows();
long includedRowCount = snapshot.getIncludedRows().size();
RangeSet destination = freeRows(includedRowCount);
for (int index = 0; index < dataColumns.length; index++) {
ColumnData dataColumn = dataColumns[index];
if (dataColumn == null) {
// no data in this column, wasn't requested
continue;
}
final int i = index;
Column column = columns.find((c, i1, i2) -> c.getIndex() == i);
ArrayCopy arrayCopy = arrayCopyFuncForColumn(column);
Object[] localCopy = new Object[(int) includedRowCount];
data[index] = localCopy;
PrimitiveIterator.OfLong destIter = destination.indexIterator();
PrimitiveIterator.OfLong indexIter = snapshot.getIncludedRows().indexIterator();
int j = 0;
while (indexIter.hasNext()) {
assert destIter.hasNext();
long dest = destIter.nextLong();
redirectedIndexes.put(indexIter.nextLong(), dest);
arrayCopy.copyTo(localCopy, dest, dataColumn.getData(), j++);
}
assert !destIter.hasNext();
}
return notifyUpdates(index, RangeSet.empty(), RangeSet.empty());
}
use of io.deephaven.web.shared.data.columns.ColumnData in project deephaven-core by deephaven.
the class JsTable method handleSnapshot.
public void handleSnapshot(TableTicket handle, TableSnapshot snapshot) {
if (!handle.equals(state().getHandle())) {
return;
}
Viewport viewport = getBinding().getSubscription();
if (viewport == null || viewport.getRows() == null || viewport.getRows().size() == 0) {
// check out if we have a non-viewport sub attached
if (nonViewportSub != null) {
nonViewportSub.handleSnapshot(snapshot);
}
return;
}
RangeSet viewportRows = viewport.getRows();
JsLog.debug("handleSnapshot on " + viewportRows, handle, snapshot, viewport);
RangeSet includedRows = snapshot.getIncludedRows();
ColumnData[] dataColumns = snapshot.getDataColumns();
JsArray[] remappedData = new JsArray[dataColumns.length];
// remap dataColumns to the expected range for that table's viewport
long lastRow = -1;
for (int col = viewport.getColumns().nextSetBit(0); col >= 0; col = viewport.getColumns().nextSetBit(col + 1)) {
ColumnData dataColumn = dataColumns[col];
if (dataColumn == null) {
// TODO when IDS-2138 is fixed stop throwing this data away
return;
}
Object columnData = dataColumn.getData();
final ColumnDefinition def = state().getTableDef().getColumns()[col];
remappedData[col] = JsData.newArray(def.getType());
PrimitiveIterator.OfLong viewportIterator = viewportRows.indexIterator();
PrimitiveIterator.OfLong includedRowsIterator = includedRows.indexIterator();
int dataIndex = 0;
while (viewportIterator.hasNext()) {
long viewportIndex = viewportIterator.nextLong();
if (viewportIndex >= snapshot.getTableSize()) {
// reached or passed the end of the table, we'll still make a snapshot
break;
}
if (!includedRowsIterator.hasNext()) {
// TODO when IDS-2138 is fixed stop throwing this data away
return;
}
long possibleMatch = includedRowsIterator.nextLong();
while (includedRowsIterator.hasNext() && possibleMatch < viewportIndex) {
// skip, still seeking to the next item
dataIndex++;
possibleMatch = includedRowsIterator.nextLong();
}
if (!includedRowsIterator.hasNext() && possibleMatch < viewportIndex) {
// we didn't find any items which match, just give up
return;
}
if (possibleMatch > viewportIndex) {
// rest of this table entirely, a later update will get us caught up
return;
}
Object data = Js.<JsArray<Object>>uncheckedCast(columnData).getAt(dataIndex);
remappedData[col].push(data);
// increment for the next row
dataIndex++;
// Track how many rows were actually present, allowing the snapshot to stop before the viewport's end
lastRow = Math.max(lastRow, possibleMatch);
}
}
// TODO correct this - assumes max one range per table viewport, and nothing skipped
RangeSet actualViewport = lastRow == -1 ? RangeSet.empty() : RangeSet.ofRange(viewportRows.indexIterator().nextLong(), lastRow);
handleSnapshot(handle, snapshot.getSnapshotType(), actualViewport, remappedData, viewport.getColumns(), viewportRows.size());
}
Aggregations