use of com.facebook.presto.RowPageBuilder in project presto by prestodb.
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");
MapType mapType = new MapType(keyType, new ArrayType(valueType));
Signature signature = new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), keyType.getTypeSignature(), valueType.getTypeSignature());
InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(signature);
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(aggFunc, map.isEmpty() ? null : map, builder.build().getBlocks());
}
use of com.facebook.presto.RowPageBuilder in project presto by prestodb.
the class TestLearnAggregations method getPage.
private static Page getPage() throws JsonProcessingException {
Type mapType = typeManager.getParameterizedType("map", ImmutableList.of(TypeSignatureParameter.of(parseTypeSignature(StandardTypes.BIGINT)), TypeSignatureParameter.of(parseTypeSignature(StandardTypes.DOUBLE))));
int datapoints = 100;
RowPageBuilder builder = RowPageBuilder.rowPageBuilder(BigintType.BIGINT, mapType, VarcharType.VARCHAR);
Random rand = new Random(0);
for (int i = 0; i < datapoints; i++) {
long label = rand.nextDouble() < 0.5 ? 0 : 1;
builder.row(label, mapSliceOf(BigintType.BIGINT, DoubleType.DOUBLE, 0, label + rand.nextGaussian()), "C=1");
}
return builder.build();
}
Aggregations