Search in sources :

Example 1 with RowPageBuilder

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());
}
Also used : ArrayType(com.facebook.presto.type.ArrayType) HashMap(java.util.HashMap) Signature(com.facebook.presto.metadata.Signature) RowPageBuilder(com.facebook.presto.RowPageBuilder) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MapType(com.facebook.presto.type.MapType)

Example 2 with RowPageBuilder

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();
}
Also used : ClassifierParametricType(com.facebook.presto.ml.type.ClassifierParametricType) RegressorType(com.facebook.presto.ml.type.RegressorType) DoubleType(com.facebook.presto.spi.type.DoubleType) Type(com.facebook.presto.spi.type.Type) BigintType(com.facebook.presto.spi.type.BigintType) ModelType(com.facebook.presto.ml.type.ModelType) ClassifierType(com.facebook.presto.ml.type.ClassifierType) VarcharType(com.facebook.presto.spi.type.VarcharType) Random(java.util.Random) RowPageBuilder(com.facebook.presto.RowPageBuilder)

Aggregations

RowPageBuilder (com.facebook.presto.RowPageBuilder)2 Signature (com.facebook.presto.metadata.Signature)1 ClassifierParametricType (com.facebook.presto.ml.type.ClassifierParametricType)1 ClassifierType (com.facebook.presto.ml.type.ClassifierType)1 ModelType (com.facebook.presto.ml.type.ModelType)1 RegressorType (com.facebook.presto.ml.type.RegressorType)1 BigintType (com.facebook.presto.spi.type.BigintType)1 DoubleType (com.facebook.presto.spi.type.DoubleType)1 Type (com.facebook.presto.spi.type.Type)1 VarcharType (com.facebook.presto.spi.type.VarcharType)1 ArrayType (com.facebook.presto.type.ArrayType)1 MapType (com.facebook.presto.type.MapType)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1