use of io.crate.execution.engine.aggregation.statistics.Variance in project crate by crate.
the class VarianceAggregation method getDocValueAggregator.
@Nullable
@Override
public DocValueAggregator<?> getDocValueAggregator(List<Reference> aggregationReferences, DocTableInfo table, List<Literal<?>> optionalParams) {
Reference reference = aggregationReferences.get(0);
if (!reference.hasDocValues()) {
return null;
}
switch(reference.valueType().id()) {
case ByteType.ID:
case ShortType.ID:
case IntegerType.ID:
case LongType.ID:
case TimestampType.ID_WITH_TZ:
case TimestampType.ID_WITHOUT_TZ:
return new SortedNumericDocValueAggregator<>(reference.column().fqn(), (ramAccounting, memoryManager, minNodeVersion) -> {
ramAccounting.addBytes(VarianceStateType.INSTANCE.fixedSize());
return new Variance();
}, (values, state) -> state.increment(values.nextValue()));
case FloatType.ID:
return new SortedNumericDocValueAggregator<>(reference.column().fqn(), (ramAccounting, memoryManager, minNodeVersion) -> {
ramAccounting.addBytes(VarianceStateType.INSTANCE.fixedSize());
return new Variance();
}, (values, state) -> {
var value = NumericUtils.sortableIntToFloat((int) values.nextValue());
state.increment(value);
});
case DoubleType.ID:
return new SortedNumericDocValueAggregator<>(reference.column().fqn(), (ramAccounting, memoryManager, minNodeVersion) -> {
ramAccounting.addBytes(VarianceStateType.INSTANCE.fixedSize());
return new Variance();
}, (values, state) -> {
var value = NumericUtils.sortableLongToDouble((values.nextValue()));
state.increment(value);
});
default:
return null;
}
}
Aggregations