use of org.apache.datasketches.hll.Union 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;
}
};
}
use of org.apache.datasketches.hll.Union in project druid by druid-io.
the class HllSketchAggregatorFactory method combine.
@Override
public HllSketch combine(final Object objectA, final Object objectB) {
final Union union = new Union(lgK);
union.update((HllSketch) objectA);
union.update((HllSketch) objectB);
return union.getResult(tgtHllType);
}
use of org.apache.datasketches.hll.Union in project druid by druid-io.
the class HllSketchMergeBufferAggregatorHelper method get.
/**
* Helper for implementing {@link org.apache.druid.query.aggregation.BufferAggregator#get} and
* {@link org.apache.druid.query.aggregation.VectorAggregator#get}.
*/
public Object get(ByteBuffer buf, int position) {
final WritableMemory mem = WritableMemory.writableWrap(buf, ByteOrder.LITTLE_ENDIAN).writableRegion(position, size);
final Union union = Union.writableWrap(mem);
return union.getResult(tgtHllType);
}
use of org.apache.datasketches.hll.Union in project druid by druid-io.
the class HllSketchMergeBufferAggregator method aggregate.
@Override
public void aggregate(final ByteBuffer buf, final int position) {
final HllSketch sketch = selector.getObject();
if (sketch == null) {
return;
}
final WritableMemory mem = WritableMemory.writableWrap(buf, ByteOrder.LITTLE_ENDIAN).writableRegion(position, helper.getSize());
final Union union = Union.writableWrap(mem);
union.update(sketch);
}
use of org.apache.datasketches.hll.Union in project druid by druid-io.
the class HllSketchMergeVectorAggregator method aggregate.
@Override
public void aggregate(final ByteBuffer buf, final int numRows, final int[] positions, @Nullable final int[] rows, final int positionOffset) {
final Object[] vector = objectSupplier.get();
for (int i = 0; i < numRows; i++) {
final HllSketch o = (HllSketch) vector[rows != null ? rows[i] : i];
if (o != null) {
final int position = positions[i] + positionOffset;
final WritableMemory mem = WritableMemory.writableWrap(buf, ByteOrder.LITTLE_ENDIAN).writableRegion(position, helper.getSize());
final Union union = Union.writableWrap(mem);
union.update(o);
}
}
}
Aggregations