Search in sources :

Example 1 with BufferAggregator

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

the class LongLastAggregationTest method testLongLastBufferAggregator.

@Test
public void testLongLastBufferAggregator() {
    BufferAggregator agg = longLastAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longLastAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
    Assert.assertEquals(times[2], result.lhs.longValue());
    Assert.assertEquals(longValues[2], result.rhs.longValue());
    Assert.assertEquals(longValues[2], agg.getLong(buffer, 0));
    Assert.assertEquals(longValues[2], agg.getFloat(buffer, 0), 1);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) SerializablePair(org.apache.druid.collections.SerializablePair) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 2 with BufferAggregator

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

the class LongLastAggregationTest method testLongLastBufferAggregatorWithTimeColumn.

@Test
public void testLongLastBufferAggregatorWithTimeColumn() {
    BufferAggregator agg = new LongLastAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longLastAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
    Assert.assertEquals(customTimes[1], result.lhs.longValue());
    Assert.assertEquals(longValues[1], result.rhs.longValue());
    Assert.assertEquals(longValues[1], agg.getLong(buffer, 0));
    Assert.assertEquals(longValues[1], agg.getFloat(buffer, 0), 1);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) SerializablePair(org.apache.druid.collections.SerializablePair) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 3 with BufferAggregator

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

the class LongLastAggregationTest method testLongLastCombiningBufferAggregator.

@Test
public void testLongLastCombiningBufferAggregator() {
    BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longLastAggFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Long> result = (Pair<Long, Long>) agg.get(buffer, 0);
    Pair<Long, Long> expected = (Pair<Long, Long>) pairs[2];
    Assert.assertEquals(expected.lhs, result.lhs);
    Assert.assertEquals(expected.rhs, result.rhs);
    Assert.assertEquals(expected.rhs.longValue(), agg.getLong(buffer, 0));
    Assert.assertEquals(expected.rhs, agg.getFloat(buffer, 0), 1);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) SerializablePair(org.apache.druid.collections.SerializablePair) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 4 with BufferAggregator

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

the class FloatLastAggregationTest method testFloatLastCombiningBufferAggregator.

@Test
public void testFloatLastCombiningBufferAggregator() {
    BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[floatLastAggregatorFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Float> result = (Pair<Long, Float>) agg.get(buffer, 0);
    Pair<Long, Float> expected = (Pair<Long, Float>) pairs[2];
    Assert.assertEquals(expected.lhs, result.lhs);
    Assert.assertEquals(expected.rhs, result.rhs, 0.0001);
    Assert.assertEquals(expected.rhs.longValue(), agg.getLong(buffer, 0));
    Assert.assertEquals(expected.rhs, agg.getFloat(buffer, 0), 0.0001);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) SerializablePair(org.apache.druid.collections.SerializablePair) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 5 with BufferAggregator

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

the class FloatLastAggregationTest method testFloatLastBufferAggregatorWithTimeColumn.

@Test
public void testFloatLastBufferAggregatorWithTimeColumn() {
    BufferAggregator agg = new FloatLastAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[floatLastAggregatorFactory.getMaxIntermediateSizeWithNulls()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, Float> result = (Pair<Long, Float>) agg.get(buffer, 0);
    Assert.assertEquals(customTimes[1], result.lhs.longValue());
    Assert.assertEquals(floats[1], result.rhs, 0.0001);
    Assert.assertEquals((long) floats[1], agg.getLong(buffer, 0));
    Assert.assertEquals(floats[1], agg.getFloat(buffer, 0), 0.0001);
}
Also used : BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) SerializablePair(org.apache.druid.collections.SerializablePair) Pair(org.apache.druid.java.util.common.Pair) 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