use of io.trino.RowPageBuilder 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.RowPageBuilder in project trino by trinodb.
the class TestMultimapAggAggregation method testMultimapAgg.
private static <K, V> void testMultimapAgg(Type keyType, List<K> expectedKeys, Type valueType, List<V> expectedValues) {
checkState(expectedKeys.size() == expectedValues.size(), "expectedKeys and expectedValues should have equal size");
Map<K, List<V>> map = new HashMap<>();
for (int i = 0; i < expectedKeys.size(); i++) {
if (!map.containsKey(expectedKeys.get(i))) {
map.put(expectedKeys.get(i), new ArrayList<>());
}
map.get(expectedKeys.get(i)).add(expectedValues.get(i));
}
RowPageBuilder builder = RowPageBuilder.rowPageBuilder(keyType, valueType);
for (int i = 0; i < expectedKeys.size(); i++) {
builder.row(expectedKeys.get(i), expectedValues.get(i));
}
assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MultimapAggregationFunction.NAME), fromTypes(keyType, valueType), map.isEmpty() ? null : map, builder.build());
}
use of io.trino.RowPageBuilder in project trino by trinodb.
the class TestLearnAggregations method getPage.
private static Page getPage() {
Type mapType = TESTING_TYPE_MANAGER.getParameterizedType("map", ImmutableList.of(typeParameter(BIGINT.getTypeSignature()), typeParameter(DOUBLE.getTypeSignature())));
int datapoints = 100;
RowPageBuilder builder = RowPageBuilder.rowPageBuilder(BIGINT, mapType, VARCHAR);
Random rand = new Random(0);
for (int i = 0; i < datapoints; i++) {
long label = rand.nextDouble() < 0.5 ? 0 : 1;
builder.row(label, mapBlockOf(BIGINT, DOUBLE, 0L, label + rand.nextGaussian()), "C=1");
}
return builder.build();
}
Aggregations