use of io.trino.operator.aggregation.groupby.AggregationTestOutput in project trino by trinodb.
the class TestMultimapAggAggregation method testMultimapAggWithGroupBy.
private static <K, V> void testMultimapAggWithGroupBy(TestingAggregationFunction aggregationFunction, GroupedAggregator groupedAggregator, 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.runPagesOnAggregatorWithAssertion(groupId, aggregationFunction.getFinalType(), groupedAggregator, testOutput);
}
use of io.trino.operator.aggregation.groupby.AggregationTestOutput in project trino by trinodb.
the class TestHistogram method testManyValuesInducingRehash.
private static void testManyValuesInducingRehash(TestingAggregationFunction aggregationFunction) {
double distinctFraction = 0.1f;
int numGroups = 50000;
int itemCount = 30;
Random random = new Random();
GroupedAggregator groupedAggregator = aggregationFunction.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()).createGroupedAggregator();
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.runPagesOnAggregatorWithAssertion(j, aggregationFunction.getFinalType(), groupedAggregator, new AggregationTestOutput(expectedValues));
}
}
use of io.trino.operator.aggregation.groupby.AggregationTestOutput in project trino by trinodb.
the class TestHistogram method testSharedGroupByWithOverlappingValuesRunner.
private static void testSharedGroupByWithOverlappingValuesRunner(TestingAggregationFunction 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).buildOrThrow());
AggregationTestInput test1 = testInputBuilder1.build();
test1.runPagesOnAggregatorWithAssertion(0L, aggregationFunction.getFinalType(), test1.createGroupedAggregator(), aggregationTestOutput1);
}
use of io.trino.operator.aggregation.groupby.AggregationTestOutput in project trino by trinodb.
the class TestArrayAggregation method testMultipleGroupsWithMultiplePages.
@Test
public void testMultipleGroupsWithMultiplePages() {
TestingAggregationFunction varcharAgg = FUNCTION_RESOLUTION.getAggregateFunction(QualifiedName.of("array_agg"), fromTypes(VARCHAR));
Block block1 = createStringsBlock("a", "b", "c", "d", "e");
Block block2 = createStringsBlock("f", "g", "h", "i", "j");
AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableList.of("a", "b", "c", "d", "e"));
AggregationTestInputBuilder testInputBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, varcharAgg);
AggregationTestInput test1 = testInputBuilder1.build();
GroupedAggregator groupedAggregator = test1.createGroupedAggregator();
test1.runPagesOnAggregatorWithAssertion(0L, varcharAgg.getFinalType(), groupedAggregator, aggregationTestOutput1);
AggregationTestOutput aggregationTestOutput2 = new AggregationTestOutput(ImmutableList.of("f", "g", "h", "i", "j"));
AggregationTestInputBuilder testBuilder2 = new AggregationTestInputBuilder(new Block[] { block2 }, varcharAgg);
AggregationTestInput test2 = testBuilder2.build();
test2.runPagesOnAggregatorWithAssertion(255L, varcharAgg.getFinalType(), groupedAggregator, aggregationTestOutput2);
}
use of io.trino.operator.aggregation.groupby.AggregationTestOutput in project trino by trinodb.
the class TestArrayAggregation method testManyValues.
@Test
public void testManyValues() {
// Test many values so multiple BlockBuilders will be used to store group state.
TestingAggregationFunction varcharAgg = FUNCTION_RESOLUTION.getAggregateFunction(QualifiedName.of("array_agg"), fromTypes(VARCHAR));
int numGroups = 50000;
int arraySize = 30;
Random random = new Random();
GroupedAggregator groupedAggregator = varcharAgg.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()).createGroupedAggregator();
for (int j = 0; j < numGroups; j++) {
List<String> expectedValues = new ArrayList<>();
List<String> valueList = new ArrayList<>();
for (int i = 0; i < arraySize; i++) {
String str = String.valueOf(random.nextInt());
valueList.add(str);
expectedValues.add(str);
}
Block block = createStringsBlock(valueList);
AggregationTestInputBuilder testInputBuilder = new AggregationTestInputBuilder(new Block[] { block }, varcharAgg);
AggregationTestInput test1 = testInputBuilder.build();
test1.runPagesOnAggregatorWithAssertion(j, varcharAgg.getFinalType(), groupedAggregator, new AggregationTestOutput(expectedValues));
}
}
Aggregations