Search in sources :

Example 31 with Signature

use of com.facebook.presto.metadata.Signature in project presto by prestodb.

the class TestMinMaxByNAggregation method testMinDoubleDouble.

@Test
public void testMinDoubleDouble() throws Exception {
    InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("min_by", AGGREGATE, parseTypeSignature("array(double)"), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.DOUBLE), parseTypeSignature(StandardTypes.BIGINT)));
    assertAggregation(function, Arrays.asList((Double) null), createDoublesBlock(1.0, null), createDoublesBlock(5.0, 3.0), createRLEBlock(1L, 2));
    assertAggregation(function, null, createDoublesBlock(null, null), createDoublesBlock(null, null), createRLEBlock(1L, 2));
    assertAggregation(function, ImmutableList.of(2.0), createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(1L, 4));
    assertAggregation(function, ImmutableList.of(2.0, 5.0), createDoublesBlock(2.5, 2.0, 5.0, 3.0), createDoublesBlock(4.0, 1.5, 2.0, 3.0), createRLEBlock(2L, 4));
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 32 with Signature

use of com.facebook.presto.metadata.Signature in project presto by prestodb.

the class TestMinMaxByNAggregation method testMinArrayVarchar.

@Test
public void testMinArrayVarchar() {
    InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("min_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT)));
    assertAggregation(function, ImmutableList.of("b", "x", "z"), createStringsBlock("z", "a", "x", "b"), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(0L, 3L), ImmutableList.of(0L, 2L))), createRLEBlock(3L, 4));
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 33 with Signature

use of com.facebook.presto.metadata.Signature in project presto by prestodb.

the class TestMinMaxByNAggregation method testMaxArrayVarchar.

@Test
public void testMaxArrayVarchar() {
    InternalAggregationFunction function = METADATA.getFunctionRegistry().getAggregateFunctionImplementation(new Signature("max_by", AGGREGATE, parseTypeSignature("array(varchar)"), parseTypeSignature(StandardTypes.VARCHAR), parseTypeSignature("array(bigint)"), parseTypeSignature(StandardTypes.BIGINT)));
    assertAggregation(function, ImmutableList.of("a", "z", "x"), createStringsBlock("z", "a", "x", "b"), createArrayBigintBlock(ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(2L, 3L), ImmutableList.of(0L, 3L), ImmutableList.of(0L, 2L))), createRLEBlock(3L, 4));
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) Test(org.testng.annotations.Test)

Example 34 with Signature

use of com.facebook.presto.metadata.Signature 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 35 with Signature

use of com.facebook.presto.metadata.Signature in project presto by prestodb.

the class TestMapAggAggregation method testDoubleMapMap.

@Test
public void testDoubleMapMap() throws Exception {
    MapType innerMapType = new MapType(VARCHAR, VARCHAR);
    MapType mapType = new MapType(DOUBLE, innerMapType);
    InternalAggregationFunction aggFunc = metadata.getFunctionRegistry().getAggregateFunctionImplementation(new Signature(NAME, AGGREGATE, mapType.getTypeSignature(), parseTypeSignature(StandardTypes.DOUBLE), innerMapType.getTypeSignature()));
    BlockBuilder builder = innerMapType.createBlockBuilder(new BlockBuilderStatus(), 3);
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("a", "b")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("c", "d")));
    innerMapType.writeObject(builder, mapBlockOf(VARCHAR, VARCHAR, ImmutableMap.of("e", "f")));
    assertAggregation(aggFunc, ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"), 3.0, ImmutableMap.of("e", "f")), createDoublesBlock(1.0, 2.0, 3.0), builder.build());
}
Also used : Signature(com.facebook.presto.metadata.Signature) TypeSignature.parseTypeSignature(com.facebook.presto.spi.type.TypeSignature.parseTypeSignature) MapType(com.facebook.presto.type.MapType) BlockBuilder(com.facebook.presto.spi.block.BlockBuilder) BlockBuilderStatus(com.facebook.presto.spi.block.BlockBuilderStatus) Test(org.testng.annotations.Test)

Aggregations

Signature (com.facebook.presto.metadata.Signature)123 TypeSignature.parseTypeSignature (com.facebook.presto.spi.type.TypeSignature.parseTypeSignature)96 Test (org.testng.annotations.Test)91 MapType (com.facebook.presto.type.MapType)18 ImmutableList (com.google.common.collect.ImmutableList)16 RowExpression (com.facebook.presto.sql.relational.RowExpression)12 TypeSignature (com.facebook.presto.spi.type.TypeSignature)11 FunctionCall (com.facebook.presto.sql.tree.FunctionCall)11 Block (com.facebook.presto.spi.block.Block)10 Type (com.facebook.presto.spi.type.Type)10 InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)8 Page (com.facebook.presto.spi.Page)8 DecimalType (com.facebook.presto.spi.type.DecimalType)8 CallExpression (com.facebook.presto.sql.relational.CallExpression)8 MethodHandle (java.lang.invoke.MethodHandle)8 MetadataManager (com.facebook.presto.metadata.MetadataManager)7 PlanNode (com.facebook.presto.sql.planner.plan.PlanNode)7 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)7 ConstantExpression (com.facebook.presto.sql.relational.ConstantExpression)7 BlockBuilder (com.facebook.presto.spi.block.BlockBuilder)6