All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.engine.table.impl.replay.ReplayLastByGroupedTable Maven / Gradle / Ivy

There is a newer version: 0.36.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.engine.table.impl.replay;

import io.deephaven.engine.rowset.RowSet;
import io.deephaven.engine.rowset.RowSetBuilderRandom;
import io.deephaven.engine.rowset.RowSetFactory;
import io.deephaven.engine.rowset.TrackingRowSet;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.util.*;
import io.deephaven.time.DateTimeUtils;

import java.time.Instant;
import java.util.Map;

public class ReplayLastByGroupedTable extends QueryReplayGroupedTable {

    public ReplayLastByGroupedTable(TrackingRowSet rowSet, Map> input,
            String timeColumn,
            Replayer replayer, String[] groupingColumns) {
        super("ReplayLastByGroupedTable", rowSet, input, timeColumn, replayer,
                WritableRowRedirection.FACTORY.createRowRedirection(100), groupingColumns);
        // noinspection unchecked
        replayer.registerTimeSource(rowSet, (ColumnSource) input.get(timeColumn));
    }

    @Override
    public void run() {
        if (allIterators.isEmpty()) {
            return;
        }
        RowSetBuilderRandom addedBuilder = RowSetFactory.builderRandom();
        RowSetBuilderRandom modifiedBuilder = RowSetFactory.builderRandom();
        // List iteratorsToAddBack = new ArrayList<>(allIterators.size());
        while (!allIterators.isEmpty()
                && DateTimeUtils.epochNanos(allIterators.peek().lastTime) < replayer.clock().currentTimeNanos()) {
            IteratorsAndNextTime currentIt = allIterators.poll();
            rowRedirection.put(currentIt.pos, currentIt.lastIndex);
            if (getRowSet().find(currentIt.pos) >= 0) {
                modifiedBuilder.addKey(currentIt.pos);
            } else {
                addedBuilder.addKey(currentIt.pos);
            }
            do {
                currentIt = currentIt.next();
            } while (currentIt != null
                    && DateTimeUtils.epochNanos(currentIt.lastTime) < replayer.clock().currentTimeNanos());
            if (currentIt != null) {
                allIterators.add(currentIt);
            }
        }
        final RowSet added = addedBuilder.build();
        final RowSet modified = modifiedBuilder.build();
        if (!added.isEmpty() || !modified.isEmpty()) {
            getRowSet().writableCast().insert(added);
            notifyListeners(added, RowSetFactory.empty(), modified);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy