@Override public ArrayOfDoublesSketch apply(final int nominalEntries, final int numberOfValues, final ArrayOfDoublesSketch[] sketches) { final ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(nominalEntries) .setNumberOfValues(numberOfValues).buildUnion(); for (final ArrayOfDoublesSketch sketch : sketches) { union.update(sketch); } return union.getResult(); } },
@Override public ArrayOfDoublesSketch apply(final int nominalEntries, final int numberOfValues, final ArrayOfDoublesSketch[] sketches) { final ArrayOfDoublesIntersection intersection = new ArrayOfDoublesSetOperationBuilder() .setNominalEntries(nominalEntries).setNumberOfValues(numberOfValues).buildIntersection(); for (final ArrayOfDoublesSketch sketch : sketches) { intersection.update(sketch, COMBINER); } return intersection.getResult(); } },
public ArrayOfDoublesSketchNoOpAggregator(final int numberOfValues) { emptySketch = new ArrayOfDoublesUpdatableSketchBuilder().setNumberOfValues(numberOfValues).build().compact(); }
public ArrayOfDoublesSketchBuildAggregator( final DimensionSelector keySelector, final List<BaseDoubleColumnValueSelector> valueSelectors, final int nominalEntries ) { this.keySelector = keySelector; this.valueSelectors = valueSelectors.toArray(new BaseDoubleColumnValueSelector[0]); values = new double[valueSelectors.size()]; sketch = new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(nominalEntries) .setNumberOfValues(valueSelectors.size()).build(); }
private static SummaryStatistics[] getStats(final ArrayOfDoublesSketch sketch) { final SummaryStatistics[] stats = new SummaryStatistics[sketch.getNumValues()]; Arrays.setAll(stats, i -> new SummaryStatistics()); final ArrayOfDoublesSketchIterator it = sketch.iterator(); while (it.next()) { final double[] values = it.getValues(); for (int i = 0; i < values.length; i++) { stats[i].addValue(values[i]); } } return stats; }
public ArrayOfDoublesSketchMergeAggregator( final BaseObjectColumnValueSelector<ArrayOfDoublesSketch> selector, final int nominalEntries, final int numberOfValues ) { this.selector = selector; union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(nominalEntries).setNumberOfValues(numberOfValues) .buildUnion(); }
@Override public Object finalizeComputation(final Object object) { return ((ArrayOfDoublesSketch) object).getEstimate(); }
/** * This method uses synchronization because it can be used during indexing, * and Druid can call aggregate() and get() concurrently * https://github.com/apache/incubator-druid/pull/3956 * The returned sketch is a separate instance of ArrayOfDoublesCompactSketch * representing the current state of the aggregation, and is not affected by consequent * aggregate() calls */ @Override public synchronized Object get() { return sketch.compact(); }
@Override public ArrayOfDoublesSketch getObject() { return union.getResult(); }
public static ArrayOfDoublesSketch deserializeFromByteArray(final byte[] data) { final Memory mem = Memory.wrap(data); return ArrayOfDoublesSketches.wrapSketch(mem); }
@Override public int getMaxIntermediateSize() { return ArrayOfDoublesUnion.getMaxBytes(nominalEntries, numberOfValues); }
@Override public void fold(final ColumnValueSelector selector) { final ArrayOfDoublesSketch sketch = (ArrayOfDoublesSketch) selector.getObject(); union.update(sketch); }
@Override public void reset(final ColumnValueSelector selector) { union.reset(); fold(selector); }
@Override @Nullable public byte[] toBytes(@Nullable final ArrayOfDoublesSketch sketch) { if (sketch == null) { return null; } return sketch.toByteArray(); }
@Override public Object combine(@Nullable final Object lhs, @Nullable final Object rhs) { final ArrayOfDoublesUnion union = new ArrayOfDoublesSetOperationBuilder().setNominalEntries(nominalEntries) .setNumberOfValues(numberOfValues).buildUnion(); if (lhs != null) { union.update((ArrayOfDoublesSketch) lhs); } if (rhs != null) { union.update((ArrayOfDoublesSketch) rhs); } return union.getResult(); }
public ArrayOfDoublesSketchNoOpBufferAggregator(final int numberOfValues) { emptySketch = new ArrayOfDoublesUpdatableSketchBuilder().setNumberOfValues(numberOfValues).build().compact(); }
@Override public void init(final ByteBuffer buf, final int position) { final WritableMemory mem = WritableMemory.wrap(buf, ByteOrder.LITTLE_ENDIAN); final WritableMemory region = mem.writableRegion(position, maxIntermediateSize); new ArrayOfDoublesUpdatableSketchBuilder().setNominalEntries(nominalEntries) .setNumberOfValues(valueSelectors.length) .setNumberOfValues(valueSelectors.length).build(region); }
@Override public void init(final ByteBuffer buf, final int position) { final WritableMemory mem = WritableMemory.wrap(buf, ByteOrder.LITTLE_ENDIAN); final WritableMemory region = mem.writableRegion(position, maxIntermediateSize); new ArrayOfDoublesSetOperationBuilder().setNominalEntries(nominalEntries) .setNumberOfValues(numberOfValues).buildUnion(region); }
/** * This method uses synchronization because it can be used during indexing, * and Druid can call aggregate() and get() concurrently * https://github.com/apache/incubator-druid/pull/3956 * The returned sketch is a separate instance of ArrayOfDoublesCompactSketch * representing the current state of the aggregation, and is not affected by consequent * aggregate() calls */ @Override public synchronized Object get() { return union.getResult(); }
@Override public void serialize( final ArrayOfDoublesSketch sketch, final JsonGenerator generator, final SerializerProvider provider ) throws IOException { generator.writeBinary(sketch.toByteArray()); }