use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput in project presto by prestodb.
the class TestMultimapAggAggregation method testMultimapAggWithGroupBy.
private static <K, V> void testMultimapAggWithGroupBy(InternalAggregationFunction aggregationFunction, GroupedAccumulator groupedAccumulator, int groupId, Type keyType, List<K> expectedKeys, Type valueType, List<V> expectedValues) {
RowPageBuilder pageBuilder = RowPageBuilder.rowPageBuilder(keyType, valueType);
ImmutableMultimap.Builder<K, V> outputBuilder = ImmutableMultimap.builder();
for (int i = 0; i < expectedValues.size(); i++) {
pageBuilder.row(expectedKeys.get(i), expectedValues.get(i));
outputBuilder.put(expectedKeys.get(i), expectedValues.get(i));
}
Page page = pageBuilder.build();
AggregationTestInput input = new AggregationTestInputBuilder(new Block[] { page.getBlock(0), page.getBlock(1) }, aggregationFunction).build();
AggregationTestOutput testOutput = new AggregationTestOutput(outputBuilder.build().asMap());
input.runPagesOnAccumulatorWithAssertion(groupId, groupedAccumulator, testOutput);
}
use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput in project presto by prestodb.
the class TestHistogram method testSharedGroupByWithOverlappingValuesRunner.
private void testSharedGroupByWithOverlappingValuesRunner(InternalAggregationFunction aggregationFunction) {
Block block1 = createStringsBlock("a", "b", "c", "d", "a1", "b2", "c3", "d4", "a", "b2", "c", "d4", "a3", "b3", "c3", "b2");
AggregationTestInputBuilder testInputBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, aggregationFunction);
AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableMap.<String, Long>builder().put("a", 2L).put("b", 1L).put("c", 2L).put("d", 1L).put("a1", 1L).put("b2", 3L).put("c3", 2L).put("d4", 2L).put("a3", 1L).put("b3", 1L).build());
AggregationTestInput test1 = testInputBuilder1.build();
test1.runPagesOnAccumulatorWithAssertion(0L, test1.createGroupedAccumulator(), aggregationTestOutput1);
}
use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput in project presto by prestodb.
the class TestHistogram method testSharedGroupByWithOverlappingValuesPerGroupRunner.
private void testSharedGroupByWithOverlappingValuesPerGroupRunner(InternalAggregationFunction aggregationFunction) {
Block block1 = createStringsBlock("a", "b", "c");
Block block2 = createStringsBlock("b", "c", "d");
AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableMap.of("a", 1L, "b", 1L, "c", 1L));
AggregationTestInputBuilder testBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, aggregationFunction);
AggregationTestInput test1 = testBuilder1.build();
GroupedAccumulator groupedAccumulator = test1.createGroupedAccumulator();
test1.runPagesOnAccumulatorWithAssertion(0L, groupedAccumulator, aggregationTestOutput1);
AggregationTestOutput aggregationTestOutput2 = new AggregationTestOutput(ImmutableMap.of("b", 1L, "c", 1L, "d", 1L));
AggregationTestInputBuilder testbuilder2 = new AggregationTestInputBuilder(new Block[] { block2 }, aggregationFunction);
AggregationTestInput test2 = testbuilder2.build();
test2.runPagesOnAccumulatorWithAssertion(255L, groupedAccumulator, aggregationTestOutput2);
}
use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput in project presto by prestodb.
the class TestHistogram method testManyValuesInducingRehash.
private void testManyValuesInducingRehash(InternalAggregationFunction aggregationFunction) {
double distinctFraction = 0.1f;
int numGroups = 50000;
int itemCount = 30;
Random random = new Random();
GroupedAccumulator groupedAccumulator = createGroupedAccumulator(aggregationFunction);
for (int j = 0; j < numGroups; j++) {
Map<String, Long> expectedValues = new HashMap<>();
List<String> valueList = new ArrayList<>();
for (int i = 0; i < itemCount; i++) {
String str = String.valueOf(i % 10);
String item = IntStream.range(0, itemCount).mapToObj(x -> str).collect(Collectors.joining());
boolean distinctValue = random.nextDouble() < distinctFraction;
if (distinctValue) {
// produce a unique value for the histogram
item = j + "-" + item;
valueList.add(item);
} else {
valueList.add(item);
}
expectedValues.compute(item, (k, v) -> v == null ? 1L : ++v);
}
Block block = createStringsBlock(valueList);
AggregationTestInputBuilder testInputBuilder = new AggregationTestInputBuilder(new Block[] { block }, aggregationFunction);
AggregationTestInput test1 = testInputBuilder.build();
test1.runPagesOnAccumulatorWithAssertion(j, groupedAccumulator, new AggregationTestOutput(expectedValues));
}
}
use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput in project presto by prestodb.
the class TestHistogram method testSharedGroupByWithDistinctValuesPerGroupRunner.
private void testSharedGroupByWithDistinctValuesPerGroupRunner(InternalAggregationFunction aggregationFunction) {
Block block1 = createStringsBlock("a", "b", "c");
Block block2 = createStringsBlock("d", "e", "f");
AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableMap.of("a", 1L, "b", 1L, "c", 1L));
AggregationTestInputBuilder testInputBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, aggregationFunction);
AggregationTestInput test1 = testInputBuilder1.build();
GroupedAccumulator groupedAccumulator = test1.createGroupedAccumulator();
test1.runPagesOnAccumulatorWithAssertion(0L, groupedAccumulator, aggregationTestOutput1);
AggregationTestOutput aggregationTestOutput2 = new AggregationTestOutput(ImmutableMap.of("d", 1L, "e", 1L, "f", 1L));
AggregationTestInputBuilder testBuilder2 = new AggregationTestInputBuilder(new Block[] { block2 }, aggregationFunction);
AggregationTestInput test2 = testBuilder2.build();
test2.runPagesOnAccumulatorWithAssertion(255L, groupedAccumulator, aggregationTestOutput2);
}
Aggregations