Search in sources :

Example 11 with HyperLogLogCollector

use of org.apache.druid.hll.HyperLogLogCollector in project druid by druid-io.

the class HyperUniquesBufferAggregator method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position) {
    HyperLogLogCollector collector = (HyperLogLogCollector) selector.getObject();
    if (collector == null) {
        return;
    }
    // Save position, limit and restore later instead of allocating a new ByteBuffer object
    final int oldPosition = buf.position();
    final int oldLimit = buf.limit();
    buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
    buf.position(position);
    try {
        HyperLogLogCollector.makeCollector(buf).fold(collector);
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 12 with HyperLogLogCollector

use of org.apache.druid.hll.HyperLogLogCollector in project druid by druid-io.

the class HyperUniquesVectorAggregator method aggregate.

@Override
public void aggregate(final ByteBuffer buf, final int position, final int startRow, final int endRow) {
    // Save position, limit and restore later instead of allocating a new ByteBuffer object
    final int oldPosition = buf.position();
    final int oldLimit = buf.limit();
    buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
    buf.position(position);
    try {
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        final Object[] vector = selector.getObjectVector();
        for (int i = startRow; i < endRow; i++) {
            final HyperLogLogCollector otherCollector = (HyperLogLogCollector) vector[i];
            if (otherCollector != null) {
                collector.fold(otherCollector);
            }
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 13 with HyperLogLogCollector

use of org.apache.druid.hll.HyperLogLogCollector in project druid by druid-io.

the class HyperUniquesVectorAggregator 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 = selector.getObjectVector();
    for (int i = 0; i < numRows; i++) {
        final HyperLogLogCollector otherCollector = (HyperLogLogCollector) vector[rows != null ? rows[i] : i];
        if (otherCollector == null) {
            continue;
        }
        final int position = positions[i] + positionOffset;
        // Save position, limit and restore later instead of allocating a new ByteBuffer object
        final int oldPosition = buf.position();
        final int oldLimit = buf.limit();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        try {
            HyperLogLogCollector.makeCollector(buf).fold(otherCollector);
        } finally {
            buf.limit(oldLimit);
            buf.position(oldPosition);
        }
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 14 with HyperLogLogCollector

use of org.apache.druid.hll.HyperLogLogCollector in project druid by druid-io.

the class CardinalityBufferAggregator method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position) {
    // Save position, limit and restore later instead of allocating a new ByteBuffer object
    final int oldPosition = buf.position();
    final int oldLimit = buf.limit();
    try {
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        if (byRow) {
            CardinalityAggregator.hashRow(selectorPluses, collector);
        } else {
            CardinalityAggregator.hashValues(selectorPluses, collector);
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 15 with HyperLogLogCollector

use of org.apache.druid.hll.HyperLogLogCollector in project druid by druid-io.

the class HyperLogLogCollectorAggregateCombiner method fold.

@Override
public void fold(ColumnValueSelector selector) {
    HyperLogLogCollector other = (HyperLogLogCollector) selector.getObject();
    if (other == null) {
        return;
    }
    if (combined == null) {
        combined = HyperLogLogCollector.makeLatestCollector();
    }
    combined.fold(other);
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Aggregations

HyperLogLogCollector (org.apache.druid.hll.HyperLogLogCollector)41 Test (org.junit.Test)12 Random (java.util.Random)4 InputRow (org.apache.druid.data.input.InputRow)4 ByteBuffer (java.nio.ByteBuffer)3 ArrayList (java.util.ArrayList)3 Comparator (java.util.Comparator)3 HashMap (java.util.HashMap)3 VersionZeroHyperLogLogCollector (org.apache.druid.hll.VersionZeroHyperLogLogCollector)3 Expr (org.apache.druid.math.expr.Expr)3 ExprEval (org.apache.druid.math.expr.ExprEval)3 HyperUniquesAggregatorFactory (org.apache.druid.query.aggregation.hyperloglog.HyperUniquesAggregatorFactory)3 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)3 Interval (org.joda.time.Interval)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Optional (com.google.common.base.Optional)2 ImmutableList (com.google.common.collect.ImmutableList)2 HashFunction (com.google.common.hash.HashFunction)2 File (java.io.File)2 List (java.util.List)2