Search in sources :

Example 1 with ObjectAggregateCombiner

use of org.apache.druid.query.aggregation.ObjectAggregateCombiner in project druid by druid-io.

the class HllSketchAggregatorFactory method makeAggregateCombiner.

@Override
public AggregateCombiner makeAggregateCombiner() {
    return new ObjectAggregateCombiner<HllSketch>() {

        private final Union union = new Union(lgK);

        @Override
        public void reset(final ColumnValueSelector selector) {
            union.reset();
            fold(selector);
        }

        @Override
        public void fold(final ColumnValueSelector selector) {
            final HllSketch sketch = (HllSketch) selector.getObject();
            union.update(sketch);
        }

        @Nullable
        @Override
        public HllSketch getObject() {
            return union.getResult(tgtHllType);
        }

        @Override
        public Class<HllSketch> classOfObject() {
            return HllSketch.class;
        }
    };
}
Also used : HllSketch(org.apache.datasketches.hll.HllSketch) ObjectAggregateCombiner(org.apache.druid.query.aggregation.ObjectAggregateCombiner) Union(org.apache.datasketches.hll.Union) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector)

Example 2 with ObjectAggregateCombiner

use of org.apache.druid.query.aggregation.ObjectAggregateCombiner in project druid by druid-io.

the class DoublesSketchAggregatorFactory method makeAggregateCombiner.

@Override
public AggregateCombiner makeAggregateCombiner() {
    return new ObjectAggregateCombiner<DoublesSketch>() {

        private final DoublesUnion union = DoublesUnion.builder().setMaxK(k).build();

        @Override
        public void reset(final ColumnValueSelector selector) {
            union.reset();
            fold(selector);
        }

        @Override
        public void fold(final ColumnValueSelector selector) {
            final DoublesSketch sketch = (DoublesSketch) selector.getObject();
            union.update(sketch);
        }

        @Nullable
        @Override
        public DoublesSketch getObject() {
            return union.getResult();
        }

        @Override
        public Class<DoublesSketch> classOfObject() {
            return DoublesSketch.class;
        }
    };
}
Also used : DoublesSketch(org.apache.datasketches.quantiles.DoublesSketch) DoublesUnion(org.apache.datasketches.quantiles.DoublesUnion) ObjectAggregateCombiner(org.apache.druid.query.aggregation.ObjectAggregateCombiner) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) NilColumnValueSelector(org.apache.druid.segment.NilColumnValueSelector) BaseDoubleColumnValueSelector(org.apache.druid.segment.BaseDoubleColumnValueSelector)

Example 3 with ObjectAggregateCombiner

use of org.apache.druid.query.aggregation.ObjectAggregateCombiner in project druid by druid-io.

the class TDigestSketchAggregatorFactory method makeAggregateCombiner.

@Override
public AggregateCombiner makeAggregateCombiner() {
    return new ObjectAggregateCombiner<MergingDigest>() {

        private MergingDigest combined = new MergingDigest(compression);

        @Override
        public void reset(final ColumnValueSelector selector) {
            combined = null;
            fold(selector);
        }

        @Override
        public void fold(final ColumnValueSelector selector) {
            MergingDigest other = (MergingDigest) selector.getObject();
            if (other == null) {
                return;
            }
            if (combined == null) {
                combined = new MergingDigest(compression);
            }
            combined.add(other);
        }

        @Nullable
        @Override
        public MergingDigest getObject() {
            return combined;
        }

        @Override
        public Class<MergingDigest> classOfObject() {
            return MergingDigest.class;
        }
    };
}
Also used : MergingDigest(com.tdunning.math.stats.MergingDigest) ObjectAggregateCombiner(org.apache.druid.query.aggregation.ObjectAggregateCombiner) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector)

Example 4 with ObjectAggregateCombiner

use of org.apache.druid.query.aggregation.ObjectAggregateCombiner in project druid by druid-io.

the class ArrayOfDoublesSketchAggregatorFactory method makeAggregateCombiner.

@Override
public AggregateCombiner makeAggregateCombiner() {
    return new ObjectAggregateCombiner<ArrayOfDoublesSketch>() {

        private final ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(nominalEntries).setNumberOfValues(numberOfValues).buildUnion();

        @Override
        public void reset(final ColumnValueSelector selector) {
            union.reset();
            fold(selector);
        }

        @Override
        public void fold(final ColumnValueSelector selector) {
            final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) selector.getObject();
            union.union(sketch);
        }

        @Override
        public ArrayOfDoublesSketch getObject() {
            return union.getResult();
        }

        @Override
        public Class<ArrayOfDoublesSketch> classOfObject() {
            return ArrayOfDoublesSketch.class;
        }
    };
}
Also used : ArrayOfDoublesUnion(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUnion) ArrayOfDoublesSetOperationBuilder(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSetOperationBuilder) ObjectAggregateCombiner(org.apache.druid.query.aggregation.ObjectAggregateCombiner) ArrayOfDoublesSketch(org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch) ColumnValueSelector(org.apache.druid.segment.ColumnValueSelector) NilColumnValueSelector(org.apache.druid.segment.NilColumnValueSelector) BaseObjectColumnValueSelector(org.apache.druid.segment.BaseObjectColumnValueSelector) BaseDoubleColumnValueSelector(org.apache.druid.segment.BaseDoubleColumnValueSelector)

Aggregations

ObjectAggregateCombiner (org.apache.druid.query.aggregation.ObjectAggregateCombiner)4 ColumnValueSelector (org.apache.druid.segment.ColumnValueSelector)4 BaseDoubleColumnValueSelector (org.apache.druid.segment.BaseDoubleColumnValueSelector)2 NilColumnValueSelector (org.apache.druid.segment.NilColumnValueSelector)2 MergingDigest (com.tdunning.math.stats.MergingDigest)1 HllSketch (org.apache.datasketches.hll.HllSketch)1 Union (org.apache.datasketches.hll.Union)1 DoublesSketch (org.apache.datasketches.quantiles.DoublesSketch)1 DoublesUnion (org.apache.datasketches.quantiles.DoublesUnion)1 ArrayOfDoublesSetOperationBuilder (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSetOperationBuilder)1 ArrayOfDoublesSketch (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch)1 ArrayOfDoublesUnion (org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUnion)1 BaseObjectColumnValueSelector (org.apache.druid.segment.BaseObjectColumnValueSelector)1