Search in sources :

Example 46 with Aggregator

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

the class FloatFirstAggregationTest method testFloatFirstCombiningAggregator.

@Test
public void testFloatFirstCombiningAggregator() {
    Aggregator agg = combiningAggFactory.factorize(colSelectorFactory);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    Pair<Long, Float> result = (Pair<Long, Float>) agg.get();
    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());
    Assert.assertEquals(expected.rhs, agg.getFloat(), 0.0001);
}
Also used : Aggregator(org.apache.druid.query.aggregation.Aggregator) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) 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 47 with Aggregator

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

the class FloatFirstAggregationTest method testFloatFirstAggregatorWithTimeColumn.

@Test
public void testFloatFirstAggregatorWithTimeColumn() {
    Aggregator agg = new FloatFirstAggregatorFactory("billy", "nilly", "customTime").factorize(colSelectorFactory);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    Pair<Long, Float> result = (Pair<Long, Float>) agg.get();
    Assert.assertEquals(customTimes[1], result.lhs.longValue());
    Assert.assertEquals(floats[1], result.rhs, 0.0001);
    Assert.assertEquals((long) floats[1], agg.getLong());
    Assert.assertEquals(floats[1], agg.getDouble(), 0.0001);
}
Also used : Aggregator(org.apache.druid.query.aggregation.Aggregator) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) 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 48 with Aggregator

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

the class StringFirstAggregationTest method testStringFirstCombiningAggregator.

@Test
public void testStringFirstCombiningAggregator() {
    Aggregator agg = combiningAggFactory.factorize(colSelectorFactory);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    Pair<Long, String> result = (Pair<Long, String>) agg.get();
    Pair<Long, String> expected = pairs[3];
    Assert.assertEquals(expected.lhs, result.lhs);
    Assert.assertEquals(expected.rhs, result.rhs);
}
Also used : Aggregator(org.apache.druid.query.aggregation.Aggregator) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 49 with Aggregator

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

the class StringFirstAggregationTest method testStringFirstAggregatorWithTimeColumn.

@Test
public void testStringFirstAggregatorWithTimeColumn() {
    Aggregator agg = new StringFirstAggregatorFactory("billy", "nilly", "customTime", MAX_STRING_SIZE).factorize(colSelectorFactory);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    aggregate(agg);
    Pair<Long, String> result = (Pair<Long, String>) agg.get();
    Assert.assertEquals(strings[1], result.rhs);
}
Also used : Aggregator(org.apache.druid.query.aggregation.Aggregator) BufferAggregator(org.apache.druid.query.aggregation.BufferAggregator) SerializablePairLongString(org.apache.druid.query.aggregation.SerializablePairLongString) Pair(org.apache.druid.java.util.common.Pair) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Example 50 with Aggregator

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

the class IncrementalIndexIngestionTest method testOnHeapIncrementalIndexClose.

@Test
public void testOnHeapIncrementalIndexClose() throws Exception {
    // Prepare the mocks & set close() call count expectation to 1
    Aggregator mockedAggregator = EasyMock.createMock(LongMaxAggregator.class);
    mockedAggregator.close();
    EasyMock.expectLastCall().times(1);
    final IncrementalIndex genericIndex = indexCreator.createIndex(new IncrementalIndexSchema.Builder().withQueryGranularity(Granularities.MINUTE).withMetrics(new LongMaxAggregatorFactory("max", "max")).build());
    // This test is specific to the on-heap index
    if (!(genericIndex instanceof OnheapIncrementalIndex)) {
        return;
    }
    final OnheapIncrementalIndex index = (OnheapIncrementalIndex) genericIndex;
    index.add(new MapBasedInputRow(0, Collections.singletonList("billy"), ImmutableMap.of("billy", 1, "max", 1)));
    // override the aggregators with the mocks
    index.concurrentGet(0)[0] = mockedAggregator;
    // close the indexer and validate the expectations
    EasyMock.replay(mockedAggregator);
    index.close();
    EasyMock.verify(mockedAggregator);
}
Also used : LongMaxAggregator(org.apache.druid.query.aggregation.LongMaxAggregator) Aggregator(org.apache.druid.query.aggregation.Aggregator) MapBasedInputRow(org.apache.druid.data.input.MapBasedInputRow) LongMaxAggregatorFactory(org.apache.druid.query.aggregation.LongMaxAggregatorFactory) InitializedNullHandlingTest(org.apache.druid.testing.InitializedNullHandlingTest) Test(org.junit.Test)

Aggregations

Aggregator (org.apache.druid.query.aggregation.Aggregator)63 Test (org.junit.Test)50 BufferAggregator (org.apache.druid.query.aggregation.BufferAggregator)35 InitializedNullHandlingTest (org.apache.druid.testing.InitializedNullHandlingTest)30 Pair (org.apache.druid.java.util.common.Pair)24 SerializablePair (org.apache.druid.collections.SerializablePair)18 PostAggregator (org.apache.druid.query.aggregation.PostAggregator)18 HashMap (java.util.HashMap)12 FieldAccessPostAggregator (org.apache.druid.query.aggregation.post.FieldAccessPostAggregator)12 TestDoubleColumnSelectorImpl (org.apache.druid.query.aggregation.TestDoubleColumnSelectorImpl)9 AggregatorFactory (org.apache.druid.query.aggregation.AggregatorFactory)7 SerializablePairLongString (org.apache.druid.query.aggregation.SerializablePairLongString)6 TestObjectColumnSelector (org.apache.druid.query.aggregation.TestObjectColumnSelector)4 ArrayList (java.util.ArrayList)3 MapBasedInputRow (org.apache.druid.data.input.MapBasedInputRow)3 GroupByQueryRunnerTest (org.apache.druid.query.groupby.GroupByQueryRunnerTest)3 Cursor (org.apache.druid.segment.Cursor)3 InputRow (org.apache.druid.data.input.InputRow)2 MapBasedRow (org.apache.druid.data.input.MapBasedRow)2 ParseException (org.apache.druid.java.util.common.parsers.ParseException)2