Search in sources :

Example 1 with AggregationTestInputBuilder

use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder in project presto by prestodb.

the class TestMultimapAggAggregation method testMultimapAggWithGroupBy.

private static <K, V> void testMultimapAggWithGroupBy(InternalAggregationFunction aggregationFunction, GroupedAccumulator groupedAccumulator, 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.runPagesOnAccumulatorWithAssertion(groupId, groupedAccumulator, testOutput);
}
Also used : AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) RowPageBuilder(com.facebook.presto.RowPageBuilder) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) Block(com.facebook.presto.common.block.Block) Page(com.facebook.presto.common.Page) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)

Example 2 with AggregationTestInputBuilder

use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder in project presto by prestodb.

the class TestHistogram method testSharedGroupByWithOverlappingValuesRunner.

private void testSharedGroupByWithOverlappingValuesRunner(InternalAggregationFunction 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).build());
    AggregationTestInput test1 = testInputBuilder1.build();
    test1.runPagesOnAccumulatorWithAssertion(0L, test1.createGroupedAccumulator(), aggregationTestOutput1);
}
Also used : AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) BlockAssertions.createStringArraysBlock(com.facebook.presto.block.BlockAssertions.createStringArraysBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) Block(com.facebook.presto.common.block.Block) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)

Example 3 with AggregationTestInputBuilder

use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder in project presto by prestodb.

the class TestHistogram method testSharedGroupByWithOverlappingValuesPerGroupRunner.

private void testSharedGroupByWithOverlappingValuesPerGroupRunner(InternalAggregationFunction aggregationFunction) {
    Block block1 = createStringsBlock("a", "b", "c");
    Block block2 = createStringsBlock("b", "c", "d");
    AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableMap.of("a", 1L, "b", 1L, "c", 1L));
    AggregationTestInputBuilder testBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, aggregationFunction);
    AggregationTestInput test1 = testBuilder1.build();
    GroupedAccumulator groupedAccumulator = test1.createGroupedAccumulator();
    test1.runPagesOnAccumulatorWithAssertion(0L, groupedAccumulator, aggregationTestOutput1);
    AggregationTestOutput aggregationTestOutput2 = new AggregationTestOutput(ImmutableMap.of("b", 1L, "c", 1L, "d", 1L));
    AggregationTestInputBuilder testbuilder2 = new AggregationTestInputBuilder(new Block[] { block2 }, aggregationFunction);
    AggregationTestInput test2 = testbuilder2.build();
    test2.runPagesOnAccumulatorWithAssertion(255L, groupedAccumulator, aggregationTestOutput2);
}
Also used : AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) BlockAssertions.createStringArraysBlock(com.facebook.presto.block.BlockAssertions.createStringArraysBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) Block(com.facebook.presto.common.block.Block) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)

Example 4 with AggregationTestInputBuilder

use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder in project presto by prestodb.

the class TestHistogram method testManyValuesInducingRehash.

private void testManyValuesInducingRehash(InternalAggregationFunction aggregationFunction) {
    double distinctFraction = 0.1f;
    int numGroups = 50000;
    int itemCount = 30;
    Random random = new Random();
    GroupedAccumulator groupedAccumulator = createGroupedAccumulator(aggregationFunction);
    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.runPagesOnAccumulatorWithAssertion(j, groupedAccumulator, new AggregationTestOutput(expectedValues));
    }
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DateTimeZone(org.joda.time.DateTimeZone) MetadataManager(com.facebook.presto.metadata.MetadataManager) Test(org.testng.annotations.Test) Random(java.util.Random) TimeZoneKey.getTimeZoneKey(com.facebook.presto.common.type.TimeZoneKey.getTimeZoneKey) Map(java.util.Map) BlockAssertions.createStringArraysBlock(com.facebook.presto.block.BlockAssertions.createStringArraysBlock) StructuralTestUtil.mapBlockOf(com.facebook.presto.util.StructuralTestUtil.mapBlockOf) NEW(com.facebook.presto.operator.aggregation.histogram.HistogramGroupImplementation.NEW) DateTimeZoneIndex.getDateTimeZone(com.facebook.presto.util.DateTimeZoneIndex.getDateTimeZone) Ints(org.testng.internal.collections.Ints) BlockBuilder(com.facebook.presto.common.block.BlockBuilder) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) HistogramGroupImplementation(com.facebook.presto.operator.aggregation.histogram.HistogramGroupImplementation) OperatorAssertion.toRow(com.facebook.presto.operator.OperatorAssertion.toRow) Collectors(java.util.stream.Collectors) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) List(java.util.List) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) Optional(java.util.Optional) UpdateMemory(com.facebook.presto.operator.UpdateMemory) AggregationTestUtils.assertAggregation(com.facebook.presto.operator.aggregation.AggregationTestUtils.assertAggregation) IntStream(java.util.stream.IntStream) MapType(com.facebook.presto.common.type.MapType) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) TIMESTAMP_WITH_TIME_ZONE(com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) HashMap(java.util.HashMap) TypeSignatureProvider.fromTypes(com.facebook.presto.sql.analyzer.TypeSignatureProvider.fromTypes) ArrayList(java.util.ArrayList) GroupByAggregationTestUtils(com.facebook.presto.operator.aggregation.groupByAggregations.GroupByAggregationTestUtils) AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) ImmutableList(com.google.common.collect.ImmutableList) NAME(com.facebook.presto.operator.aggregation.histogram.Histogram.NAME) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) ArrayType(com.facebook.presto.common.type.ArrayType) StructuralTestUtil.mapType(com.facebook.presto.util.StructuralTestUtil.mapType) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) Type(com.facebook.presto.common.type.Type) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) SqlTimestampWithTimeZone(com.facebook.presto.common.type.SqlTimestampWithTimeZone) DateTime(org.joda.time.DateTime) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) TimeZoneKey(com.facebook.presto.common.type.TimeZoneKey) DateTimeEncoding.packDateTimeWithZone(com.facebook.presto.common.type.DateTimeEncoding.packDateTimeWithZone) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) RowType(com.facebook.presto.common.type.RowType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Random(java.util.Random) AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) BlockAssertions.createStringArraysBlock(com.facebook.presto.block.BlockAssertions.createStringArraysBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) Block(com.facebook.presto.common.block.Block) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)

Example 5 with AggregationTestInputBuilder

use of com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder in project presto by prestodb.

the class TestHistogram method testSharedGroupByWithDistinctValuesPerGroupRunner.

private void testSharedGroupByWithDistinctValuesPerGroupRunner(InternalAggregationFunction aggregationFunction) {
    Block block1 = createStringsBlock("a", "b", "c");
    Block block2 = createStringsBlock("d", "e", "f");
    AggregationTestOutput aggregationTestOutput1 = new AggregationTestOutput(ImmutableMap.of("a", 1L, "b", 1L, "c", 1L));
    AggregationTestInputBuilder testInputBuilder1 = new AggregationTestInputBuilder(new Block[] { block1 }, aggregationFunction);
    AggregationTestInput test1 = testInputBuilder1.build();
    GroupedAccumulator groupedAccumulator = test1.createGroupedAccumulator();
    test1.runPagesOnAccumulatorWithAssertion(0L, groupedAccumulator, aggregationTestOutput1);
    AggregationTestOutput aggregationTestOutput2 = new AggregationTestOutput(ImmutableMap.of("d", 1L, "e", 1L, "f", 1L));
    AggregationTestInputBuilder testBuilder2 = new AggregationTestInputBuilder(new Block[] { block2 }, aggregationFunction);
    AggregationTestInput test2 = testBuilder2.build();
    test2.runPagesOnAccumulatorWithAssertion(255L, groupedAccumulator, aggregationTestOutput2);
}
Also used : AggregationTestOutput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput) BlockAssertions.createStringArraysBlock(com.facebook.presto.block.BlockAssertions.createStringArraysBlock) BlockAssertions.createBooleansBlock(com.facebook.presto.block.BlockAssertions.createBooleansBlock) BlockAssertions.createDoublesBlock(com.facebook.presto.block.BlockAssertions.createDoublesBlock) BlockAssertions.createLongsBlock(com.facebook.presto.block.BlockAssertions.createLongsBlock) BlockAssertions.createStringsBlock(com.facebook.presto.block.BlockAssertions.createStringsBlock) Block(com.facebook.presto.common.block.Block) AggregationTestInput(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput) AggregationTestInputBuilder(com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)

Aggregations

AggregationTestInput (com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInput)8 AggregationTestInputBuilder (com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestInputBuilder)8 AggregationTestOutput (com.facebook.presto.operator.aggregation.groupByAggregations.AggregationTestOutput)8 Block (com.facebook.presto.common.block.Block)7 BlockAssertions.createBooleansBlock (com.facebook.presto.block.BlockAssertions.createBooleansBlock)6 BlockAssertions.createLongsBlock (com.facebook.presto.block.BlockAssertions.createLongsBlock)6 BlockAssertions.createStringsBlock (com.facebook.presto.block.BlockAssertions.createStringsBlock)6 BlockAssertions.createDoublesBlock (com.facebook.presto.block.BlockAssertions.createDoublesBlock)4 BlockAssertions.createStringArraysBlock (com.facebook.presto.block.BlockAssertions.createStringArraysBlock)4 Test (org.testng.annotations.Test)4 BlockAssertions.createArrayBigintBlock (com.facebook.presto.block.BlockAssertions.createArrayBigintBlock)2 BlockAssertions.createTypedLongsBlock (com.facebook.presto.block.BlockAssertions.createTypedLongsBlock)2 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2 RowPageBuilder (com.facebook.presto.RowPageBuilder)1 Page (com.facebook.presto.common.Page)1 BlockBuilder (com.facebook.presto.common.block.BlockBuilder)1 ArrayType (com.facebook.presto.common.type.ArrayType)1 BIGINT (com.facebook.presto.common.type.BigintType.BIGINT)1 BOOLEAN (com.facebook.presto.common.type.BooleanType.BOOLEAN)1