Search in sources :

Example 31 with BufferAggregator

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

the class BaseTopNAlgorithm method makeBufferAggregators.

protected static BufferAggregator[] makeBufferAggregators(Cursor cursor, List<AggregatorFactory> aggregatorSpecs) {
    BufferAggregator[] aggregators = new BufferAggregator[aggregatorSpecs.size()];
    int aggregatorIndex = 0;
    for (AggregatorFactory spec : aggregatorSpecs) {
        aggregators[aggregatorIndex] = spec.factorizeBuffered(cursor.getColumnSelectorFactory());
        ++aggregatorIndex;
    }
    return aggregators;
}
Also used : AggregatorFactory(org.apache.druid.query.aggregation.AggregatorFactory) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator)

Example 32 with BufferAggregator

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

the class StringAnyAggregationTest method testStringAnyBufferAggregator.

@Test
public void testStringAnyBufferAggregator() {
    BufferAggregator agg = stringAnyAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[stringAnyAggFactory.getMaxIntermediateSize()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    String result = (String) agg.get(buffer, 0);
    Assert.assertEquals(strings[0], result);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 33 with BufferAggregator

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

the class FloatAnyAggregationTest method testFloatAnyBufferAggregator.

@Test
public void testFloatAnyBufferAggregator() {
    BufferAggregator agg = floatAnyAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[floatAnyAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Float result = (Float) agg.get(buffer, 0);
    Assert.assertEquals(floats[0], result, 0.0001);
    Assert.assertEquals((long) floats[0], agg.getLong(buffer, 0));
    Assert.assertEquals(floats[0], agg.getFloat(buffer, 0), 0.0001);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 34 with BufferAggregator

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

the class FloatAnyAggregationTest method testFloatAnyCombiningBufferAggregator.

@Test
public void testFloatAnyCombiningBufferAggregator() {
    BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[floatAnyAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Float result = (Float) agg.get(buffer, 0);
    Assert.assertEquals(objects[0], result, 0.0001);
    Assert.assertEquals(objects[0].longValue(), agg.getLong(buffer, 0));
    Assert.assertEquals(objects[0], agg.getFloat(buffer, 0), 0.0001);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 35 with BufferAggregator

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

the class DoubleAnyAggregationTest method testDoubleAnyBufferAggregator.

@Test
public void testDoubleAnyBufferAggregator() {
    BufferAggregator agg = doubleAnyAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[doubleAnyAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Double result = (Double) agg.get(buffer, 0);
    Assert.assertEquals(doubles[0], result, 0.0001);
    Assert.assertEquals((long) doubles[0], agg.getLong(buffer, 0));
    Assert.assertEquals(doubles[0], agg.getDouble(buffer, 0), 0.0001);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

BufferAggregator (org.apache.druid.query.aggregation.BufferAggregator)36 ByteBuffer (java.nio.ByteBuffer)33 Test (org.junit.Test)33 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)27 Pair (org.apache.druid.java.util.common.Pair)23 SerializablePair (org.apache.druid.collections.SerializablePair)18 SerializablePairLongString (org.apache.druid.query.aggregation.SerializablePairLongString)5 ColumnSelectorFactory (org.apache.druid.segment.ColumnSelectorFactory)2 Cursor (org.apache.druid.segment.Cursor)2 ImmutableList (com.google.common.collect.ImmutableList)1 Iterables (com.google.common.collect.Iterables)1 List (java.util.List)1 TimeUnit (java.util.concurrent.TimeUnit)1 Function (java.util.function.Function)1 NullHandling (org.apache.druid.common.config.NullHandling)1 Intervals (org.apache.druid.java.util.common.Intervals)1 Granularities (org.apache.druid.java.util.common.granularity.Granularities)1 Sequence (org.apache.druid.java.util.common.guava.Sequence)1 Closer (org.apache.druid.java.util.common.io.Closer)1 JavaScriptConfig (org.apache.druid.js.JavaScriptConfig)1