use of com.facebook.presto.spi.function.AggregationState in project presto by prestodb.
the class BindableAggregationFunction method getParameterMetadata.
private static List<ParameterMetadata> getParameterMetadata(@Nullable Method method, List<Type> inputTypes) {
if (method == null) {
return null;
}
ImmutableList.Builder<ParameterMetadata> builder = ImmutableList.builder();
Annotation[][] annotations = method.getParameterAnnotations();
String methodName = method.getDeclaringClass() + "." + method.getName();
checkArgument(annotations.length > 0, "At least @AggregationState argument is required for each of aggregation functions.");
int inputId = 0;
int i = 0;
if (annotations[0].length == 0) {
// Backward compatibility - first argument without annotations is interpreted as State argument
builder.add(new ParameterMetadata(STATE));
i++;
}
for (; i < annotations.length; i++) {
Annotation baseTypeAnnotation = baseTypeAnnotation(annotations[i], methodName);
if (baseTypeAnnotation instanceof SqlType) {
builder.add(fromSqlType(inputTypes.get(i - 1), isParameterBlock(annotations[i]), isParameterNullable(annotations[i]), methodName));
} else if (baseTypeAnnotation instanceof BlockIndex) {
builder.add(new ParameterMetadata(BLOCK_INDEX));
} else if (baseTypeAnnotation instanceof AggregationState) {
builder.add(new ParameterMetadata(STATE));
} else {
throw new IllegalArgumentException("Unsupported annotation: " + annotations[i]);
}
}
return builder.build();
}
use of com.facebook.presto.spi.function.AggregationState in project presto by prestodb.
the class BindableAggregationFunction method baseTypeAnnotation.
private static Annotation baseTypeAnnotation(Annotation[] annotations, String methodName) {
List<Annotation> baseTypes = Arrays.asList(annotations).stream().filter(annotation -> annotation instanceof SqlType || annotation instanceof BlockIndex || annotation instanceof AggregationState).collect(toImmutableList());
checkArgument(baseTypes.size() == 1, "Parameter of %s must have exactly one of @SqlType, @BlockIndex", methodName);
boolean nullable = isParameterNullable(annotations);
boolean isBlock = isParameterBlock(annotations);
Annotation annotation = baseTypes.get(0);
checkArgument((!isBlock && !nullable) || (annotation instanceof SqlType), "%s contains a parameter with @BlockPosition and/or @NullablePosition that is not @SqlType", methodName);
return annotation;
}
use of com.facebook.presto.spi.function.AggregationState in project presto by prestodb.
the class AggregationCompiler method findAggregationStateParamId.
public static int findAggregationStateParamId(Method method, int id) {
int currentParamId = 0;
int found = 0;
for (Annotation[] annotations : method.getParameterAnnotations()) {
for (Annotation annotation : annotations) {
if (annotation instanceof AggregationState) {
if (found++ == id) {
return currentParamId;
}
}
}
currentParamId++;
}
// some third party aggregates may assume that State will be id-th parameter
return id;
}
Aggregations