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

io.deephaven.engine.table.impl.by.BaseAddOnlyFirstOrLastChunkedOperator 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.engine.table.Table;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.engine.table.impl.sources.LongArraySource;
import io.deephaven.engine.table.impl.sources.RedirectedColumnSource;
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.table.impl.util.LongColumnSourceWritableRowRedirection;

import java.util.LinkedHashMap;
import java.util.Map;

abstract class BaseAddOnlyFirstOrLastChunkedOperator
        extends NoopStateChangeRecorder // We can never empty or reincarnate states since we're add-only
        implements IterativeChunkedAggregationOperator {

    final boolean isFirst;
    final LongArraySource redirections;
    private final LongColumnSourceWritableRowRedirection rowRedirection;
    private final Map> resultColumns;

    BaseAddOnlyFirstOrLastChunkedOperator(boolean isFirst, MatchPair[] resultPairs, Table originalTable,
            String exposeRedirectionAs) {
        this.isFirst = isFirst;
        this.redirections = new LongArraySource();
        this.rowRedirection = new LongColumnSourceWritableRowRedirection(redirections);

        this.resultColumns = new LinkedHashMap<>(resultPairs.length);
        for (final MatchPair mp : resultPairs) {
            resultColumns.put(mp.leftColumn(), RedirectedColumnSource.maybeRedirect(
                    rowRedirection, originalTable.getColumnSource(mp.rightColumn())));
        }
        if (exposeRedirectionAs != null) {
            resultColumns.put(exposeRedirectionAs, redirections);
        }
    }

    @Override
    public void removeChunk(BucketedContext bucketedContext, Chunk values,
            LongChunk inputRowKeys, IntChunk destinations,
            IntChunk startPositions, IntChunk length,
            WritableBooleanChunk stateModified) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void modifyChunk(BucketedContext bucketedContext, Chunk previousValues,
            Chunk newValues, LongChunk postShiftRowKeys,
            IntChunk destinations, IntChunk startPositions, IntChunk length,
            WritableBooleanChunk stateModified) {
        // we have no inputs, so should never get here
        throw new IllegalStateException();
    }

    @Override
    public void shiftChunk(BucketedContext bucketedContext, Chunk previousValues,
            Chunk newValues, LongChunk preShiftRowKeys,
            LongChunk postShiftRowKeys, IntChunk destinations,
            IntChunk startPositions, IntChunk length,
            WritableBooleanChunk stateModified) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void modifyRowKeys(BucketedContext context, LongChunk inputRowKeys,
            IntChunk destinations, IntChunk startPositions,
            IntChunk length,
            WritableBooleanChunk stateModified) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean removeChunk(SingletonContext singletonContext, int chunkSize, Chunk values,
            LongChunk inputRowKeys, long destination) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean modifyChunk(SingletonContext singletonContext, int chunkSize, Chunk previousValues,
            Chunk newValues, LongChunk postShiftRowKeys, long destination) {
        // we have no inputs, so should never get here
        throw new IllegalStateException();
    }

    @Override
    public boolean shiftChunk(SingletonContext singletonContext, Chunk previousValues,
            Chunk newValues, LongChunk preShiftRowKeys,
            LongChunk postShiftRowKeys, long destination) {
        throw new UnsupportedOperationException();
    }

    @Override
    public boolean modifyRowKeys(SingletonContext context, LongChunk rowKeys, long destination) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void ensureCapacity(long tableSize) {
        redirections.ensureCapacity(tableSize);
    }

    @Override
    public Map> getResultColumns() {
        return resultColumns;
    }

    @Override
    public void startTrackingPrevValues() {
        rowRedirection.startTrackingPrevValues();
    }

    @Override
    public boolean requiresRowKeys() {
        return true;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy