Search in sources :

Example 1 with RowPageBuilder

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);
}
Also used : AggregationTestOutput(io.trino.operator.aggregation.groupby.AggregationTestOutput) RowPageBuilder(io.trino.RowPageBuilder) AggregationTestInput(io.trino.operator.aggregation.groupby.AggregationTestInput) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) AggregationTestInputBuilder(io.trino.operator.aggregation.groupby.AggregationTestInputBuilder)

Example 2 with RowPageBuilder

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());
}
Also used : HashMap(java.util.HashMap) RowPageBuilder(io.trino.RowPageBuilder) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Example 3 with RowPageBuilder

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();
}
Also used : Type(io.trino.spi.type.Type) RegressorType(io.trino.plugin.ml.type.RegressorType) ClassifierParametricType(io.trino.plugin.ml.type.ClassifierParametricType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) ModelType(io.trino.plugin.ml.type.ModelType) Random(java.util.Random) RowPageBuilder(io.trino.RowPageBuilder)

Aggregations

RowPageBuilder (io.trino.RowPageBuilder)3 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMultimap (com.google.common.collect.ImmutableMultimap)1 AggregationTestInput (io.trino.operator.aggregation.groupby.AggregationTestInput)1 AggregationTestInputBuilder (io.trino.operator.aggregation.groupby.AggregationTestInputBuilder)1 AggregationTestOutput (io.trino.operator.aggregation.groupby.AggregationTestOutput)1 ClassifierParametricType (io.trino.plugin.ml.type.ClassifierParametricType)1 ModelType (io.trino.plugin.ml.type.ModelType)1 RegressorType (io.trino.plugin.ml.type.RegressorType)1 Page (io.trino.spi.Page)1 Block (io.trino.spi.block.Block)1 Type (io.trino.spi.type.Type)1 TypeSignature.mapType (io.trino.spi.type.TypeSignature.mapType)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Random (java.util.Random)1