Search in sources :

Example 11 with Aggregator

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

the class IncrementalIndexTest method testDynamicSchemaRollup.

@Test
public void testDynamicSchemaRollup() throws IndexSizeExceededException {
    IncrementalIndex<Aggregator> index = new OnheapIncrementalIndex(new IncrementalIndexSchema.Builder().withQueryGranularity(Granularities.NONE).build(), true, 10);
    closer.closeLater(index);
    index.add(new MapBasedInputRow(1481871600000L, Arrays.asList("name", "host"), ImmutableMap.<String, Object>of("name", "name1", "host", "host")));
    index.add(new MapBasedInputRow(1481871670000L, Arrays.asList("name", "table"), ImmutableMap.<String, Object>of("name", "name2", "table", "table")));
    index.add(new MapBasedInputRow(1481871600000L, Arrays.asList("name", "host"), ImmutableMap.<String, Object>of("name", "name1", "host", "host")));
    Assert.assertEquals(2, index.size());
}
Also used : OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) Aggregator(io.druid.query.aggregation.Aggregator) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) IncrementalIndexSchema(io.druid.segment.incremental.IncrementalIndexSchema) Test(org.junit.Test)

Example 12 with Aggregator

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

the class OnheapIncrementalIndexTest 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 OnheapIncrementalIndex index = new OnheapIncrementalIndex(0, Granularities.MINUTE, new AggregatorFactory[] { new LongMaxAggregatorFactory("max", "max") }, MAX_ROWS);
    index.add(new MapBasedInputRow(0, Lists.newArrayList("billy"), ImmutableMap.<String, Object>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(io.druid.query.aggregation.LongMaxAggregator) Aggregator(io.druid.query.aggregation.Aggregator) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) LongMaxAggregatorFactory(io.druid.query.aggregation.LongMaxAggregatorFactory) Test(org.junit.Test)

Example 13 with Aggregator

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

the class SearchQueryRunnerTest method testSearchWithNullValueInDimension.

@Test
public void testSearchWithNullValueInDimension() throws Exception {
    IncrementalIndex<Aggregator> index = new OnheapIncrementalIndex(new IncrementalIndexSchema.Builder().withQueryGranularity(Granularities.NONE).withMinTimestamp(new DateTime("2011-01-12T00:00:00.000Z").getMillis()).build(), true, 10);
    index.add(new MapBasedInputRow(1481871600000L, Arrays.asList("name", "host"), ImmutableMap.<String, Object>of("name", "name1", "host", "host")));
    index.add(new MapBasedInputRow(1481871670000L, Arrays.asList("name", "table"), ImmutableMap.<String, Object>of("name", "name2", "table", "table")));
    SearchQuery searchQuery = Druids.newSearchQueryBuilder().dimensions(new DefaultDimensionSpec("table", "table")).dataSource(QueryRunnerTestHelper.dataSource).granularity(QueryRunnerTestHelper.allGran).intervals(QueryRunnerTestHelper.fullOnInterval).context(ImmutableMap.<String, Object>of("searchStrategy", "cursorOnly")).build();
    QueryRunnerFactory factory = new SearchQueryRunnerFactory(selector, toolChest, QueryRunnerTestHelper.NOOP_QUERYWATCHER);
    QueryRunner runner = factory.createRunner(new QueryableIndexSegment("asdf", TestIndex.persistRealtimeAndLoadMMapped(index)));
    List<SearchHit> expectedHits = Lists.newLinkedList();
    expectedHits.add(new SearchHit("table", "table", 1));
    expectedHits.add(new SearchHit("table", "", 1));
    checkSearchQuery(searchQuery, runner, expectedHits);
}
Also used : SearchQuery(io.druid.query.search.search.SearchQuery) QueryableIndexSegment(io.druid.segment.QueryableIndexSegment) SearchHit(io.druid.query.search.search.SearchHit) OnheapIncrementalIndex(io.druid.segment.incremental.OnheapIncrementalIndex) Aggregator(io.druid.query.aggregation.Aggregator) DateTime(org.joda.time.DateTime) DefaultDimensionSpec(io.druid.query.dimension.DefaultDimensionSpec) QueryRunner(io.druid.query.QueryRunner) QueryRunnerFactory(io.druid.query.QueryRunnerFactory) MapBasedInputRow(io.druid.data.input.MapBasedInputRow) Test(org.junit.Test)

Example 14 with Aggregator

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

the class FloatTopNColumnSelectorStrategy method dimExtractionScanAndAggregate.

@Override
public void dimExtractionScanAndAggregate(TopNQuery query, FloatColumnSelector selector, Cursor cursor, Aggregator[][] rowSelector, Int2ObjectMap<Aggregator[]> aggregatesStore) {
    while (!cursor.isDone()) {
        int key = Float.floatToIntBits(selector.get());
        Aggregator[] theAggregators = aggregatesStore.get(key);
        if (theAggregators == null) {
            theAggregators = BaseTopNAlgorithm.makeAggregators(cursor, query.getAggregatorSpecs());
            aggregatesStore.put(key, theAggregators);
        }
        for (Aggregator aggregator : theAggregators) {
            aggregator.aggregate();
        }
        cursor.advance();
    }
}
Also used : Aggregator(io.druid.query.aggregation.Aggregator)

Example 15 with Aggregator

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

the class LongTopNColumnSelectorStrategy method dimExtractionScanAndAggregate.

@Override
public void dimExtractionScanAndAggregate(TopNQuery query, LongColumnSelector selector, Cursor cursor, Aggregator[][] rowSelector, Long2ObjectMap<Aggregator[]> aggregatesStore) {
    while (!cursor.isDone()) {
        long key = selector.get();
        Aggregator[] theAggregators = aggregatesStore.get(key);
        if (theAggregators == null) {
            theAggregators = BaseTopNAlgorithm.makeAggregators(cursor, query.getAggregatorSpecs());
            aggregatesStore.put(key, theAggregators);
        }
        for (Aggregator aggregator : theAggregators) {
            aggregator.aggregate();
        }
        cursor.advance();
    }
}
Also used : Aggregator(io.druid.query.aggregation.Aggregator)

Aggregations

Aggregator (io.druid.query.aggregation.Aggregator)15 Test (org.junit.Test)5 MapBasedInputRow (io.druid.data.input.MapBasedInputRow)4 AggregatorFactory (io.druid.query.aggregation.AggregatorFactory)3 OnheapIncrementalIndex (io.druid.segment.incremental.OnheapIncrementalIndex)3 ParseException (io.druid.java.util.common.parsers.ParseException)2 CountAggregatorFactory (io.druid.query.aggregation.CountAggregatorFactory)2 FilteredAggregatorFactory (io.druid.query.aggregation.FilteredAggregatorFactory)2 Cursor (io.druid.segment.Cursor)2 IndexedInts (io.druid.segment.data.IndexedInts)2 IncrementalIndexSchema (io.druid.segment.incremental.IncrementalIndexSchema)2 Supplier (com.google.common.base.Supplier)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 InputRow (io.druid.data.input.InputRow)1 DimensionsSpec (io.druid.data.input.impl.DimensionsSpec)1 QueryRunner (io.druid.query.QueryRunner)1 QueryRunnerFactory (io.druid.query.QueryRunnerFactory)1 BufferAggregator (io.druid.query.aggregation.BufferAggregator)1 CountAggregator (io.druid.query.aggregation.CountAggregator)1 DoubleSumAggregatorFactory (io.druid.query.aggregation.DoubleSumAggregatorFactory)1