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);
}
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));
}
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));
}
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));
}
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));
}
Aggregations