use of org.apache.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class SegmentMetadataQueryTest method testSegmentMetadataQueryWithAggregatorsMerge.
@Test
public void testSegmentMetadataQueryWithAggregatorsMerge() {
final Map<String, AggregatorFactory> expectedAggregators = new HashMap<>();
for (AggregatorFactory agg : TestIndex.METRIC_AGGS) {
expectedAggregators.put(agg.getName(), agg.getCombiningFactory());
}
SegmentAnalysis mergedSegmentAnalysis = new SegmentAnalysis(differentIds ? "merged" : SegmentId.dummy("testSegment").toString(), null, ImmutableMap.of("placement", new ColumnAnalysis(ColumnType.STRING, ValueType.STRING.toString(), false, false, 0, 0, null, null, null)), 0, expectedSegmentAnalysis1.getNumRows() + expectedSegmentAnalysis2.getNumRows(), expectedAggregators, null, null, null);
QueryToolChest toolChest = FACTORY.getToolchest();
ExecutorService exec = Executors.newCachedThreadPool();
QueryRunner myRunner = new FinalizeResultsQueryRunner<>(toolChest.mergeResults(FACTORY.mergeRunners(Execs.directExecutor(), Lists.newArrayList(toolChest.preMergeQueryDecoration(runner1), toolChest.preMergeQueryDecoration(runner2)))), toolChest);
SegmentMetadataQuery query = Druids.newSegmentMetadataQueryBuilder().dataSource("testing").intervals("2013/2014").toInclude(new ListColumnIncluderator(Collections.singletonList("placement"))).analysisTypes(SegmentMetadataQuery.AnalysisType.AGGREGATORS).merge(true).build();
TestHelper.assertExpectedObjects(ImmutableList.of(mergedSegmentAnalysis), myRunner.run(QueryPlus.wrap(query)), "failed SegmentMetadata merging query");
exec.shutdownNow();
}
use of org.apache.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class VectorGroupByEngineIteratorTest method testCreateOneGrouperAndCloseItWhenClose.
@Test
public void testCreateOneGrouperAndCloseItWhenClose() throws IOException {
final Interval interval = TestIndex.DATA_INTERVAL;
final AggregatorFactory factory = new DoubleSumAggregatorFactory("index", "index");
final GroupByQuery query = GroupByQuery.builder().setDataSource(QueryRunnerTestHelper.DATA_SOURCE).setGranularity(QueryRunnerTestHelper.DAY_GRAN).setInterval(interval).setDimensions(new DefaultDimensionSpec("market", null, null)).setAggregatorSpecs(factory).build();
final StorageAdapter storageAdapter = new QueryableIndexStorageAdapter(TestIndex.getMMappedTestIndex());
final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[4096]);
final VectorCursor cursor = storageAdapter.makeVectorCursor(Filters.toFilter(query.getDimFilter()), interval, query.getVirtualColumns(), false, QueryContexts.getVectorSize(query), null);
final List<GroupByVectorColumnSelector> dimensions = query.getDimensions().stream().map(dimensionSpec -> ColumnProcessors.makeVectorProcessor(dimensionSpec, GroupByVectorColumnProcessorFactory.instance(), cursor.getColumnSelectorFactory())).collect(Collectors.toList());
final MutableObject<VectorGrouper> grouperCaptor = new MutableObject<>();
final VectorGroupByEngineIterator iterator = new VectorGroupByEngineIterator(query, new GroupByQueryConfig(), storageAdapter, cursor, interval, dimensions, byteBuffer, null) {
@Override
VectorGrouper makeGrouper() {
grouperCaptor.setValue(Mockito.spy(super.makeGrouper()));
return grouperCaptor.getValue();
}
};
iterator.close();
Mockito.verify(grouperCaptor.getValue()).close();
}
use of org.apache.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class FloatLastAggregationTest method testSerde.
@Test
public void testSerde() throws Exception {
DefaultObjectMapper mapper = new DefaultObjectMapper();
String floatSpecJson = "{\"type\":\"floatLast\",\"name\":\"billy\",\"fieldName\":\"nilly\"}";
AggregatorFactory deserialized = mapper.readValue(floatSpecJson, AggregatorFactory.class);
Assert.assertEquals(floatLastAggregatorFactory, deserialized);
Assert.assertArrayEquals(floatLastAggregatorFactory.getCacheKey(), deserialized.getCacheKey());
}
use of org.apache.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class FinalizingFieldAccessPostAggregatorTest method testComparatorsWithFinalizing.
@Test
public void testComparatorsWithFinalizing() {
String aggName = "billy";
AggregatorFactory aggFactory = EasyMock.createMock(AggregatorFactory.class);
EasyMock.expect(aggFactory.finalizeComputation("test_val1")).andReturn(new Long(10L)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val2")).andReturn(new Long(21)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val3")).andReturn(new Long(3)).times(1);
EasyMock.expect(aggFactory.finalizeComputation("test_val4")).andReturn(null).times(1);
EasyMock.expect(aggFactory.getComparator()).andReturn(Ordering.natural().<Long>nullsLast()).times(1);
EasyMock.expect(aggFactory.getResultType()).andReturn(ColumnType.LONG).once();
EasyMock.replay(aggFactory);
FinalizingFieldAccessPostAggregator postAgg = buildDecorated("final_billy", aggName, ImmutableMap.of(aggName, aggFactory));
List<Object> computedValues = new ArrayList<>();
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, "test_val1")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, "test_val2")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, "test_val3")));
computedValues.add(postAgg.compute(ImmutableMap.of(aggName, "test_val4")));
Collections.sort(computedValues, postAgg.getComparator());
Assert.assertArrayEquals(new Object[] { 3L, 10L, 21L, null }, computedValues.toArray(new Object[0]));
EasyMock.verify();
}
use of org.apache.druid.query.aggregation.AggregatorFactory in project druid by druid-io.
the class FinalizingFieldAccessPostAggregatorTest method testComparatorsWithFinalizingAndComparatorNull.
@Test
public void testComparatorsWithFinalizingAndComparatorNull() {
String aggName = "billy";
AggregatorFactory aggFactory = EasyMock.createMock(AggregatorFactory.class);
EasyMock.expect(aggFactory.getComparator()).andReturn(null).times(1);
EasyMock.replay(aggFactory);
FinalizingFieldAccessPostAggregator postAgg = buildDecorated("final_billy", "joe", ImmutableMap.of(aggName, aggFactory));
List<Object> computedValues = new ArrayList<>();
Map<String, Object> forNull = new HashMap<>();
// guava does not allow the value to be null.
forNull.put("joe", null);
computedValues.add(postAgg.compute(ImmutableMap.of("joe", "test_val1")));
computedValues.add(postAgg.compute(ImmutableMap.of("joe", "test_val2")));
computedValues.add(postAgg.compute(forNull));
computedValues.add(postAgg.compute(ImmutableMap.of("joe", "test_val4")));
Collections.sort(computedValues, postAgg.getComparator());
Assert.assertArrayEquals(new Object[] { null, "test_val1", "test_val2", "test_val4" }, computedValues.toArray(new Object[0]));
EasyMock.verify();
}
Aggregations