Search in sources :

Example 1 with StandardDeviation

use of io.crate.execution.engine.aggregation.statistics.StandardDeviation in project crate by crate.

the class StandardDeviationAggregation 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(StdDevStateType.INSTANCE.fixedSize());
                return new StandardDeviation();
            }, (values, state) -> state.increment(values.nextValue()));
        case FloatType.ID:
            return new SortedNumericDocValueAggregator<>(reference.column().fqn(), (ramAccounting, memoryManager, minNodeVersion) -> {
                ramAccounting.addBytes(StdDevStateType.INSTANCE.fixedSize());
                return new StandardDeviation();
            }, (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(StdDevStateType.INSTANCE.fixedSize());
                return new StandardDeviation();
            }, (values, state) -> {
                var value = NumericUtils.sortableLongToDouble((values.nextValue()));
                state.increment(value);
            });
        default:
            return null;
    }
}
Also used : Reference(io.crate.metadata.Reference) SortedNumericDocValueAggregator(io.crate.execution.engine.aggregation.impl.templates.SortedNumericDocValueAggregator) StandardDeviation(io.crate.execution.engine.aggregation.statistics.StandardDeviation) Nullable(javax.annotation.Nullable)

Aggregations

SortedNumericDocValueAggregator (io.crate.execution.engine.aggregation.impl.templates.SortedNumericDocValueAggregator)1 StandardDeviation (io.crate.execution.engine.aggregation.statistics.StandardDeviation)1 Reference (io.crate.metadata.Reference)1 Nullable (javax.annotation.Nullable)1