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());
}
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);
}
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);
}
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();
}
}
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();
}
}
Aggregations