io.deephaven.engine.table.impl.updateby.rollingwavg.CharRollingWAvgOperator 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
package io.deephaven.engine.table.impl.updateby.rollingwavg;
import io.deephaven.chunk.CharChunk;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.impl.updateby.UpdateByOperator;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static io.deephaven.util.QueryConstants.NULL_CHAR;
import static io.deephaven.util.QueryConstants.NULL_DOUBLE;
public class CharRollingWAvgOperator extends BasePrimitiveRollingWAvgOperator {
// region extra-fields
// endregion extra-fields
protected class Context extends BasePrimitiveRollingWAvgOperator.Context {
protected CharChunk extends Values> influencerValuesChunk;
protected Context(int affectedChunkSize, int influencerChunkSize) {
super(affectedChunkSize, influencerChunkSize);
}
@Override
public void setValueChunks(@NotNull final Chunk extends Values>[] valueChunks) {
super.setValueChunks(valueChunks);
influencerValuesChunk = valueChunks[0].asCharChunk();
}
@Override
public void push(int pos, int count) {
windowValues.ensureRemaining(count);
windowWeightValues.ensureRemaining(count);
for (int ii = 0; ii < count; ii++) {
final char val = influencerValuesChunk.get(pos + ii);
final double weight = influencerWeightValuesChunk.get(pos + ii);
if (val == NULL_CHAR || weight == NULL_DOUBLE) {
windowValues.addUnsafe(NULL_DOUBLE);
windowWeightValues.addUnsafe(NULL_DOUBLE);
nullCount++;
} else {
// Compute the product and add to the agg buffer.
final double weightedVal = weight * val;
windowValues.addUnsafe(weightedVal);
windowWeightValues.addUnsafe(weight);
}
}
}
}
@NotNull
@Override
public UpdateByOperator.Context makeUpdateContext(final int affectedChunkSize, final int influencerChunkSize) {
return new Context(affectedChunkSize, influencerChunkSize);
}
public CharRollingWAvgOperator(
@NotNull final MatchPair pair,
@NotNull final String[] affectingColumns,
@Nullable final String timestampColumnName,
final long reverseWindowScaleUnits,
final long forwardWindowScaleUnits,
@NotNull final String weightColumnName
// region extra-constructor-args
// endregion extra-constructor-args
) {
super(pair, affectingColumns, timestampColumnName, reverseWindowScaleUnits, forwardWindowScaleUnits, weightColumnName);
// region constructor
// endregion constructor
}
@Override
public UpdateByOperator copy() {
return new CharRollingWAvgOperator(
pair,
affectingColumns,
timestampColumnName,
reverseWindowScaleUnits,
forwardWindowScaleUnits,
weightColumnName
// region extra-copy-args
// endregion extra-copy-args
);
}
/**
* Get the names of the input column(s) for this operator.
*
* @return the names of the input column
*/
@NotNull
@Override
protected String[] getInputColumnNames() {
return new String[] {pair.rightColumn, weightColumnName};
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy