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

io.deephaven.engine.table.impl.by.BlinkLastChunkedOperator Maven / Gradle / Ivy

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

import io.deephaven.base.verify.Assert;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.TableUpdate;
import io.deephaven.engine.table.impl.QueryTable;
import io.deephaven.chunk.*;
import io.deephaven.chunk.attributes.ChunkLengths;
import io.deephaven.chunk.attributes.ChunkPositions;
import io.deephaven.engine.rowset.chunkattributes.RowKeys;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.rowset.RowSequence;
import io.deephaven.engine.rowset.RowSet;
import org.jetbrains.annotations.NotNull;

/**
 * A lastBy aggregation operator for blink tables.
 *
 * @see Table#BLINK_TABLE_ATTRIBUTE
 */
public class BlinkLastChunkedOperator extends CopyingPermutedBlinkFirstOrLastChunkedOperator {

    BlinkLastChunkedOperator(@NotNull final MatchPair[] resultPairs, @NotNull final Table blinkTable) {
        super(resultPairs, blinkTable);
    }

    @Override
    public final boolean unchunkedRowSet() {
        return true;
    }

    @Override
    public void addChunk(final BucketedContext context, // Unused
            final Chunk values, // Unused
            @NotNull final LongChunk inputRowKeys,
            @NotNull final IntChunk destinations,
            @NotNull final IntChunk startPositions,
            @NotNull final IntChunk length,
            @NotNull final WritableBooleanChunk stateModified) {
        for (int ii = 0; ii < startPositions.size(); ++ii) {
            final int startPosition = startPositions.get(ii);
            final int runLength = length.get(ii);
            final long destination = destinations.get(startPosition);
            redirections.set(destination, inputRowKeys.get(startPosition + runLength - 1));
            stateModified.set(ii, true);
        }
    }

    @Override
    public boolean addChunk(final SingletonContext context, // Unused
            final int chunkSize,
            final Chunk values, // Unused
            @NotNull final LongChunk inputRowKeys,
            final long destination) {
        if (chunkSize == 0) {
            return false;
        }
        redirections.set(destination, inputRowKeys.get(chunkSize - 1));
        return true;
    }

    @Override
    public boolean addRowSet(final SingletonContext context,
            @NotNull final RowSet rowSet,
            final long destination) {
        if (rowSet.isEmpty()) {
            return false;
        }
        redirections.set(destination, rowSet.lastRowKey());
        return true;
    }

    @Override
    public void propagateInitialState(@NotNull final QueryTable resultTable, int startingDestinationsCount) {
        copyStreamToResult(resultTable.getRowSet());
        redirections = null;
    }

    @Override
    public void propagateUpdates(@NotNull final TableUpdate downstream,
            @NotNull final RowSet newDestinations) {
        Assert.assertion(downstream.removed().isEmpty() && downstream.shifted().empty(),
                "downstream.removed.empty() && downstream.shifted.empty()");
        try (final RowSequence changedDestinations = downstream.modified().union(downstream.added())) {
            copyStreamToResult(changedDestinations);
        }
        redirections = null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy