io.deephaven.engine.table.impl.updateby.rollingsum.FloatRollingSumOperator 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.rollingsum;
import io.deephaven.base.ringbuffer.AggregatingFloatRingBuffer;
import io.deephaven.base.verify.Assert;
import io.deephaven.chunk.Chunk;
import io.deephaven.chunk.FloatChunk;
import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.impl.MatchPair;
import io.deephaven.engine.table.impl.updateby.UpdateByOperator;
import io.deephaven.engine.table.impl.updateby.internal.BaseFloatUpdateByOperator;
import io.deephaven.engine.table.impl.util.RowRedirection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import static io.deephaven.util.QueryConstants.NULL_FLOAT;
public class FloatRollingSumOperator extends BaseFloatUpdateByOperator {
private static final int BUFFER_INITIAL_SIZE = 64;
// region extra-fields
// endregion extra-fields
protected class Context extends BaseFloatUpdateByOperator.Context {
protected FloatChunk extends Values> floatInfluencerValuesChunk;
protected AggregatingFloatRingBuffer aggSum;
protected Context(final int chunkSize) {
super(chunkSize);
aggSum = new AggregatingFloatRingBuffer(BUFFER_INITIAL_SIZE,
0,
Float::sum, // tree function
(a, b) -> { // value function
if (a == NULL_FLOAT && b == NULL_FLOAT) {
return 0; // identity val
} else if (a == NULL_FLOAT) {
return b;
} else if (b == NULL_FLOAT) {
return a;
}
return a + b;
},
true);
}
@Override
public void close() {
super.close();
}
@Override
public void setValueChunks(@NotNull final Chunk extends Values>[] valueChunks) {
floatInfluencerValuesChunk = valueChunks[0].asFloatChunk();
}
@Override
public void push(int pos, int count) {
aggSum.ensureRemaining(count);
for (int ii = 0; ii < count; ii++) {
float val = floatInfluencerValuesChunk.get(pos + ii);
aggSum.addUnsafe(val);
if (val == NULL_FLOAT) {
nullCount++;
}
}
}
@Override
public void pop(int count) {
Assert.geq(aggSum.size(), "aggSum.size()", count);
for (int ii = 0; ii < count; ii++) {
float val = aggSum.removeUnsafe();
if (val == NULL_FLOAT) {
nullCount--;
}
}
}
@Override
public void writeToOutputChunk(int outIdx) {
if (aggSum.size() == nullCount) {
outputValues.set(outIdx, NULL_FLOAT);
} else {
outputValues.set(outIdx, aggSum.evaluate());
}
}
@Override
public void reset() {
super.reset();
aggSum.clear();
}
}
@NotNull
@Override
public UpdateByOperator.Context makeUpdateContext(final int affectedChunkSize, final int influencerChunkSize) {
return new Context(affectedChunkSize);
}
public FloatRollingSumOperator(@NotNull final MatchPair pair,
@NotNull final String[] affectingColumns,
@Nullable final RowRedirection rowRedirection,
@Nullable final String timestampColumnName,
final long reverseWindowScaleUnits,
final long forwardWindowScaleUnits
// region extra-constructor-args
// endregion extra-constructor-args
) {
super(pair, affectingColumns, rowRedirection, timestampColumnName, reverseWindowScaleUnits, forwardWindowScaleUnits, true);
// region constructor
// endregion constructor
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy