io.deephaven.engine.table.impl.partitioned.LongConstantColumn Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-table Show documentation
Show all versions of deephaven-engine-table Show documentation
Engine Table: Implementation and closely-coupled utilities
/**
* Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
*/
package io.deephaven.engine.table.impl.partitioned;
import io.deephaven.chunk.ChunkType;
import io.deephaven.chunk.WritableChunk;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.rowset.RowSequence;
import io.deephaven.engine.rowset.TrackingRowSet;
import io.deephaven.engine.table.*;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.impl.select.Formula;
import io.deephaven.engine.table.impl.select.SelectColumn;
import io.deephaven.engine.table.impl.sources.LongSingleValueSource;
import io.deephaven.engine.table.impl.sources.ViewColumnSource;
import io.deephaven.util.type.TypeUtils;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* {@link SelectColumn} implementation to assign a constant {@code long} value.
*/
class LongConstantColumn implements SelectColumn {
private final String outputColumnName;
private final long outputValue;
LongConstantColumn(
@NotNull final String outputColumnName,
final long outputValue) {
this.outputColumnName = outputColumnName;
this.outputValue = outputValue;
}
@Override
public List initInputs(
@NotNull final TrackingRowSet rowSet,
@NotNull final Map> columnsOfInterest) {
return getColumns();
}
@Override
public List initDef(@NotNull final Map> columnDefinitionMap) {
return getColumns();
}
@Override
public List getColumns() {
return Collections.emptyList();
}
@NotNull
@Override
public ColumnSource> getDataView() {
return new ViewColumnSource<>(long.class, new OutputFormula(), true);
}
@Override
public String getName() {
return outputColumnName;
}
@Override
public SelectColumn copy() {
return new LongConstantColumn(outputColumnName, outputValue);
}
@Override
public final Class> getReturnedType() {
return long.class;
}
@Override
public final List getColumnArrays() {
return Collections.emptyList();
}
@NotNull
@Override
public final ColumnSource> getLazyView() {
return getDataView();
}
@Override
public final MatchPair getMatchPair() {
throw new UnsupportedOperationException();
}
@Override
public final WritableColumnSource> newDestInstance(final long size) {
return new LongSingleValueSource();
}
@Override
public final WritableColumnSource> newFlatDestInstance(final long size) {
return new LongSingleValueSource();
}
@Override
public final boolean isRetain() {
return false;
}
@Override
public final boolean isStateless() {
return true;
}
private static final class OutputFormulaFillContext implements Formula.FillContext {
private static final Formula.FillContext INSTANCE = new OutputFormulaFillContext();
private OutputFormulaFillContext() {}
@Override
public void close() {
}
}
private final class OutputFormula extends Formula {
private OutputFormula() {
super(null);
}
@Override
public Long get(final long rowKey) {
return TypeUtils.box(outputValue);
}
@Override
public Long getPrev(final long rowKey) {
return get(rowKey);
}
@Override
public long getLong(long rowKey) {
return outputValue;
}
@Override
public long getPrevLong(long rowKey) {
return getLong(rowKey);
}
@Override
protected ChunkType getChunkType() {
return ChunkType.Long;
}
@Override
public FillContext makeFillContext(final int chunkCapacity) {
return OutputFormulaFillContext.INSTANCE;
}
@Override
public void fillChunk(
@NotNull final FillContext context,
@NotNull final WritableChunk super Values> destination,
@NotNull final RowSequence rowSequence) {
destination.setSize(rowSequence.intSize());
destination.asWritableLongChunk().fillWithValue(0, destination.size(), outputValue);
}
@Override
public void fillPrevChunk(
@NotNull final FillContext context,
@NotNull final WritableChunk super Values> destination,
@NotNull final RowSequence rowSequence) {
fillChunk(context, destination, rowSequence);
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy