Search in sources :

Example 1 with Variance

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;
    }
}
Also used : Reference(io.crate.metadata.Reference) SortedNumericDocValueAggregator(io.crate.execution.engine.aggregation.impl.templates.SortedNumericDocValueAggregator) Variance(io.crate.execution.engine.aggregation.statistics.Variance) Nullable(javax.annotation.Nullable)

Aggregations

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