Search in sources :

Example 16 with HyperLogLogCollector

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

the class DoubleCardinalityVectorProcessor method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position, int startRow, 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();
    try {
        final double[] vector = selector.getDoubleVector();
        final boolean[] nullVector = selector.getNullVector();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        for (int i = startRow; i < endRow; i++) {
            if (NullHandling.replaceWithDefault() || nullVector == null || !nullVector[i]) {
                DoubleCardinalityAggregatorColumnSelectorStrategy.addDoubleToCollector(collector, vector[i]);
            }
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 17 with HyperLogLogCollector

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

the class LongCardinalityVectorProcessor method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position, int startRow, 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();
    try {
        final long[] vector = selector.getLongVector();
        final boolean[] nullVector = selector.getNullVector();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        for (int i = startRow; i < endRow; i++) {
            if (NullHandling.replaceWithDefault() || nullVector == null || !nullVector[i]) {
                LongCardinalityAggregatorColumnSelectorStrategy.addLongToCollector(collector, vector[i]);
            }
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 18 with HyperLogLogCollector

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

the class SingleValueStringCardinalityVectorProcessor method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position, int startRow, 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();
    try {
        final int[] vector = selector.getRowVector();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        for (int i = startRow; i < endRow; i++) {
            final String value = selector.lookupName(vector[i]);
            StringCardinalityAggregatorColumnSelectorStrategy.addStringToCollector(collector, value);
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 19 with HyperLogLogCollector

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

the class FloatCardinalityVectorProcessor method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position, int startRow, 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();
    try {
        final float[] vector = selector.getFloatVector();
        final boolean[] nullVector = selector.getNullVector();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        for (int i = startRow; i < endRow; i++) {
            if (NullHandling.replaceWithDefault() || nullVector == null || !nullVector[i]) {
                FloatCardinalityAggregatorColumnSelectorStrategy.addFloatToCollector(collector, vector[i]);
            }
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : HyperLogLogCollector(org.apache.druid.hll.HyperLogLogCollector)

Example 20 with HyperLogLogCollector

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

the class MultiValueStringCardinalityVectorProcessor method aggregate.

@Override
public void aggregate(ByteBuffer buf, int position, int startRow, 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();
    try {
        final IndexedInts[] vector = selector.getRowVector();
        buf.limit(position + HyperLogLogCollector.getLatestNumBytesForDenseStorage());
        buf.position(position);
        final HyperLogLogCollector collector = HyperLogLogCollector.makeCollector(buf);
        for (int i = startRow; i < endRow; i++) {
            final IndexedInts ids = vector[i];
            final int sz = ids.size();
            for (int j = 0; j < sz; j++) {
                final String value = selector.lookupName(ids.get(j));
                StringCardinalityAggregatorColumnSelectorStrategy.addStringToCollector(collector, value);
            }
        }
    } finally {
        buf.limit(oldLimit);
        buf.position(oldPosition);
    }
}
Also used : IndexedInts(org.apache.druid.segment.data.IndexedInts) 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