use of com.facebook.presto.spi.function.SqlType in project presto by prestodb.
the class CreateHll method createHll.
@ScalarFunction
@SqlType(StandardTypes.HYPER_LOG_LOG)
public static Slice createHll(@SqlType(StandardTypes.BIGINT) long value) {
HyperLogLog hll = HyperLogLog.newInstance(4096);
hll.add(value);
return hll.serialize();
}
use of com.facebook.presto.spi.function.SqlType 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.SqlType in project presto by prestodb.
the class AggregationCompiler method getInputTypesSignatures.
private static List<TypeSignature> getInputTypesSignatures(Method inputFunction) {
// FIXME Literal parameters should be part of class annotations.
ImmutableList.Builder<TypeSignature> builder = ImmutableList.builder();
Set<String> literalParameters = getLiteralParameter(inputFunction);
Annotation[][] parameterAnnotations = inputFunction.getParameterAnnotations();
for (Annotation[] annotations : parameterAnnotations) {
for (Annotation annotation : annotations) {
if (annotation instanceof SqlType) {
String typeName = ((SqlType) annotation).value();
builder.add(parseTypeSignature(typeName, literalParameters));
}
}
}
return builder.build();
}
use of com.facebook.presto.spi.function.SqlType in project presto by prestodb.
the class ArrayUnionFunction method bigintUnion.
@SqlType("array(bigint)")
public static Block bigintUnion(@SqlType("array(bigint)") Block leftArray, @SqlType("array(bigint)") Block rightArray) {
int leftArrayCount = leftArray.getPositionCount();
int rightArrayCount = rightArray.getPositionCount();
LongSet set = new LongOpenHashSet(leftArrayCount + rightArrayCount);
BlockBuilder distinctElementBlockBuilder = BIGINT.createBlockBuilder(new BlockBuilderStatus(), leftArrayCount + rightArrayCount);
AtomicBoolean containsNull = new AtomicBoolean(false);
appendBigintArray(leftArray, containsNull, set, distinctElementBlockBuilder);
appendBigintArray(rightArray, containsNull, set, distinctElementBlockBuilder);
return distinctElementBlockBuilder.build();
}
use of com.facebook.presto.spi.function.SqlType in project presto by prestodb.
the class CharacterStringCasts method varcharToCharSaturatedFloorCast.
@ScalarOperator(OperatorType.SATURATED_FLOOR_CAST)
@SqlType("char(y)")
@LiteralParameters({ "x", "y" })
public static // Char(y) value that is smaller than the original Varchar(x) value. This is fine though for usage in TupleDomainTranslator.
Slice varcharToCharSaturatedFloorCast(@LiteralParameter("y") Long y, @SqlType("varchar(x)") Slice slice) {
Slice trimmedSlice = trimSpaces(slice);
int trimmedTextLength = countCodePoints(trimmedSlice);
int numberOfTrailingSpaces = slice.length() - trimmedSlice.length();
// if Varchar(x) value length (including spaces) is greater than y, we can just truncate it
if (trimmedTextLength + numberOfTrailingSpaces >= y) {
return truncateToLength(trimmedSlice, y.intValue());
}
if (trimmedTextLength == 0) {
return EMPTY_SLICE;
}
// and also remove one additional trailing character to get smaller Char(y) value
return trimmedSlice.slice(0, offsetOfCodePoint(trimmedSlice, trimmedTextLength - 1));
}
Aggregations