Search in sources :

Example 26 with BufferAggregator

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

the class LongFirstAggregationTest method testLongFirstCombiningBufferAggregator.

@Test
public void testLongFirstCombiningBufferAggregator() {
    BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.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[0];
    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), 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 27 with BufferAggregator

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

the class LongFirstAggregationTest method testLongFirstBufferAggregatorWithTimeColumn.

@Test
public void testLongFirstBufferAggregatorWithTimeColumn() {
    BufferAggregator agg = longFirstAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[longFirstAggFactory.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[3], result.lhs.longValue());
    Assert.assertEquals(longValues[3], result.rhs.longValue());
    Assert.assertEquals(longValues[3], agg.getLong(buffer, 0));
    Assert.assertEquals(longValues[3], 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 28 with BufferAggregator

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

the class FloatFirstAggregationTest method testFloatFirstBufferAggregatorWithTimeColumn.

@Test
public void testFloatFirstBufferAggregatorWithTimeColumn() {
    BufferAggregator agg = new FloatFirstAggregatorFactory("billy", "nilly", "customTime").factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[floatFirstAggregatorFactory.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)

Example 29 with BufferAggregator

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

the class StringFirstAggregationTest method testStringFirstCombiningBufferAggregator.

@Test
public void testStringFirstCombiningBufferAggregator() {
    BufferAggregator agg = combiningAggFactory.factorizeBuffered(colSelectorFactory);
    ByteBuffer buffer = ByteBuffer.wrap(new byte[stringFirstAggFactory.getMaxIntermediateSize()]);
    agg.init(buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    aggregate(agg, buffer, 0);
    Pair<Long, String> result = (Pair<Long, String>) agg.get(buffer, 0);
    Pair<Long, String> expected = pairs[3];
    Assert.assertEquals(expected.lhs, result.lhs);
    Assert.assertEquals(expected.rhs, result.rhs);
}
Also used : SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) ByteBuffer(java.nio.ByteBuffer) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 30 with BufferAggregator

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

the class PooledTopNAlgorithm method computeSpecializedScanAndAggregateImplementations.

private static void computeSpecializedScanAndAggregateImplementations() {
    SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.clear();
    // The order of the following `if` blocks matters, "more specialized" implementations go first
    if (SPECIALIZE_HISTORICAL_SINGLE_VALUE_DIM_SELECTOR_ONE_SIMPLE_DOUBLE_AGG_POOLED_TOPN) {
        SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
            if (theAggregators.length == 1) {
                BufferAggregator aggregator = theAggregators[0];
                final Cursor cursor = params.getCursor();
                if (cursor instanceof HistoricalCursor && // doesn't clone offset anymore.
                !(((HistoricalCursor) cursor).getOffset() instanceof FilteredOffset) && aggregator instanceof SimpleDoubleBufferAggregator && params.getDimSelector() instanceof SingleValueHistoricalDimensionSelector && ((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
                    return scanAndAggregateHistorical1SimpleDoubleAgg(params, positions, (SimpleDoubleBufferAggregator) aggregator, (HistoricalCursor) cursor, DEFAULT_HISTORICAL_SINGLE_VALUE_DIM_SELECTOR_ONE_SIMPLE_DOUBLE_AGG_SCANNER);
                }
            }
            return -1;
        });
    }
    if (SPECIALIZE_HISTORICAL_ONE_SIMPLE_DOUBLE_AGG_POOLED_TOPN) {
        SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
            if (theAggregators.length == 1) {
                BufferAggregator aggregator = theAggregators[0];
                final Cursor cursor = params.getCursor();
                if (cursor instanceof HistoricalCursor && // doesn't clone offset anymore.
                !(((HistoricalCursor) cursor).getOffset() instanceof FilteredOffset) && aggregator instanceof SimpleDoubleBufferAggregator && params.getDimSelector() instanceof HistoricalDimensionSelector && ((SimpleDoubleBufferAggregator) aggregator).getSelector() instanceof HistoricalColumnSelector) {
                    return scanAndAggregateHistorical1SimpleDoubleAgg(params, positions, (SimpleDoubleBufferAggregator) aggregator, (HistoricalCursor) cursor, DEFAULT_HISTORICAL_ONE_SIMPLE_DOUBLE_AGG_SCANNER);
                }
            }
            return -1;
        });
    }
    if (SPECIALIZE_GENERIC_ONE_AGG_POOLED_TOPN) {
        SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
            if (theAggregators.length == 1) {
                return scanAndAggregateGeneric1Agg(params, positions, theAggregators[0], params.getCursor());
            }
            return -1;
        });
    }
    if (SPECIALIZE_GENERIC_TWO_AGG_POOLED_TOPN) {
        SPECIALIZED_SCAN_AND_AGGREGATE_IMPLEMENTATIONS.add((params, positions, theAggregators) -> {
            if (theAggregators.length == 2) {
                return scanAndAggregateGeneric2Agg(params, positions, theAggregators, params.getCursor());
            }
            return -1;
        });
    }
}
Also used : FilteredOffset(org.apache.druid.segment.FilteredOffset) HistoricalDimensionSelector(org.apache.druid.segment.historical.HistoricalDimensionSelector) SingleValueHistoricalDimensionSelector(org.apache.druid.segment.historical.SingleValueHistoricalDimensionSelector) HistoricalCursor(org.apache.druid.segment.historical.HistoricalCursor) SimpleDoubleBufferAggregator(org.apache.druid.query.aggregation.SimpleDoubleBufferAggregator) SingleValueHistoricalDimensionSelector(org.apache.druid.segment.historical.SingleValueHistoricalDimensionSelector) HistoricalCursor(org.apache.druid.segment.historical.HistoricalCursor) Cursor(org.apache.druid.segment.Cursor) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) SimpleDoubleBufferAggregator(org.apache.druid.query.aggregation.SimpleDoubleBufferAggregator) HistoricalColumnSelector(org.apache.druid.segment.historical.HistoricalColumnSelector)

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