Search in sources :

Example 16 with InternalAggregationFunction

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

the class ApproximateMostFrequent method specialize.

@Override
public InternalAggregationFunction specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
    Type keyType = boundVariables.getTypeVariable("K");
    checkArgument(keyType.isComparable(), "keyType must be comparable");
    Type serializedType = functionAndTypeManager.getParameterizedType(ROW, ImmutableList.of(buildTypeSignatureParameter(MAX_BUCKETS, BigintType.BIGINT), buildTypeSignatureParameter(CAPACITY, BigintType.BIGINT), buildTypeSignatureParameter(KEYS, new ArrayType(keyType)), buildTypeSignatureParameter(VALUES, new ArrayType(BigintType.BIGINT))));
    Type outputType = functionAndTypeManager.getParameterizedType(MAP, ImmutableList.of(TypeSignatureParameter.of(keyType.getTypeSignature()), TypeSignatureParameter.of(BigintType.BIGINT.getTypeSignature())));
    DynamicClassLoader classLoader = new DynamicClassLoader(ApproximateMostFrequent.class.getClassLoader());
    List<Type> inputTypes = ImmutableList.of(keyType);
    ApproximateMostFrequentStateSerializer stateSerializer = new ApproximateMostFrequentStateSerializer(keyType, serializedType);
    MethodHandle inputFunction = INPUT_FUNCTION.bindTo(keyType);
    AggregationMetadata metadata = new AggregationMetadata(generateAggregationName(NAME, outputType.getTypeSignature(), inputTypes.stream().map(Type::getTypeSignature).collect(toImmutableList())), createInputParameterMetadata(keyType), inputFunction, COMBINE_FUNCTION, OUTPUT_FUNCTION, ImmutableList.of(new AggregationMetadata.AccumulatorStateDescriptor(ApproximateMostFrequentState.class, stateSerializer, new ApproximateMostFrequentStateFactory())), outputType);
    GenericAccumulatorFactoryBinder factory = AccumulatorCompiler.generateAccumulatorFactoryBinder(metadata, classLoader);
    return new InternalAggregationFunction(NAME, inputTypes, ImmutableList.of(serializedType), outputType, true, false, factory);
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) DynamicClassLoader(com.facebook.presto.bytecode.DynamicClassLoader) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) BigintType(com.facebook.presto.common.type.BigintType) GenericAccumulatorFactoryBinder(com.facebook.presto.operator.aggregation.GenericAccumulatorFactoryBinder) AggregationMetadata(com.facebook.presto.operator.aggregation.AggregationMetadata) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) MethodHandle(java.lang.invoke.MethodHandle)

Example 17 with InternalAggregationFunction

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

the class TestIllegalMethodAggregation method testIllegalMethod.

@Test(expectedExceptions = PrestoException.class, expectedExceptionsMessageRegExp = "In differential_entropy UDF, invalid method: no_such_method")
public void testIllegalMethod() {
    FunctionAndTypeManager functionAndTypeManager = MetadataManager.createTestMetadataManager().getFunctionAndTypeManager();
    InternalAggregationFunction function = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("differential_entropy", fromTypes(BIGINT, DOUBLE, DOUBLE, VARCHAR, DOUBLE, DOUBLE)));
    aggregation(function, createLongsBlock(200), createDoublesBlock(0.1), createDoublesBlock(0.2), createStringsBlock("no_such_method"), createDoublesBlock(0.0), createDoublesBlock(1.0));
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 18 with InternalAggregationFunction

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

the class TestMinMaxByAggregation method testMinIntegerVarchar.

@Test
public void testMinIntegerVarchar() {
    InternalAggregationFunction function = getMinByAggregation(VARCHAR, INTEGER);
    assertAggregation(function, "a", createStringsBlock("a", "b", "c"), createIntsBlock(1, 2, 3));
}
Also used : InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 19 with InternalAggregationFunction

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

the class TestMinMaxByAggregation method testMinDoubleDouble.

@Test
public void testMinDoubleDouble() {
    InternalAggregationFunction function = getMinByAggregation(DOUBLE, DOUBLE);
    assertAggregation(function, null, createDoublesBlock(null, null), createDoublesBlock(null, null));
    assertAggregation(function, 3.0, createDoublesBlock(3.0, 2.0, 5.0, 3.0), createDoublesBlock(1.0, 1.5, 2.0, 4.0));
}
Also used : InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Example 20 with InternalAggregationFunction

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

the class TestMinMaxByAggregation method testMaxDoubleVarchar.

@Test
public void testMaxDoubleVarchar() {
    InternalAggregationFunction function = getMaxByAggregation(VARCHAR, DOUBLE);
    assertAggregation(function, "a", createStringsBlock("z", "a", null), createDoublesBlock(1.0, 2.0, null));
    assertAggregation(function, "hi", createStringsBlock("zz", "hi", null, "a"), createDoublesBlock(0.0, 1.0, null, -1.0));
}
Also used : InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction) Test(org.testng.annotations.Test)

Aggregations

InternalAggregationFunction (com.facebook.presto.operator.aggregation.InternalAggregationFunction)89 Test (org.testng.annotations.Test)73 ArrayType (com.facebook.presto.common.type.ArrayType)31 AggregationMetadata (com.facebook.presto.operator.aggregation.AggregationMetadata)20 Type (com.facebook.presto.common.type.Type)17 ParametricAggregation (com.facebook.presto.operator.aggregation.ParametricAggregation)14 AggregationImplementation (com.facebook.presto.operator.aggregation.AggregationImplementation)13 TypeSignature (com.facebook.presto.common.type.TypeSignature)12 TypeSignature.parseTypeSignature (com.facebook.presto.common.type.TypeSignature.parseTypeSignature)12 Signature (com.facebook.presto.spi.function.Signature)12 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)9 DynamicClassLoader (com.facebook.presto.bytecode.DynamicClassLoader)8 Page (com.facebook.presto.common.Page)8 GenericAccumulatorFactoryBinder (com.facebook.presto.operator.aggregation.GenericAccumulatorFactoryBinder)8 AccumulatorStateDescriptor (com.facebook.presto.operator.aggregation.AggregationMetadata.AccumulatorStateDescriptor)7 RowPagesBuilder (com.facebook.presto.RowPagesBuilder)6 HashAggregationOperatorFactory (com.facebook.presto.operator.HashAggregationOperator.HashAggregationOperatorFactory)6 DataSize (io.airlift.units.DataSize)6 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)5 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)4