use of com.facebook.presto.spi.function.OperatorType.CAST in project presto by prestodb.
the class DecimalCasts method castFunctionFromDecimalTo.
private static SqlScalarFunction castFunctionFromDecimalTo(TypeSignature to, String... methodNames) {
Signature signature = Signature.builder().kind(SCALAR).operatorType(CAST).argumentTypes(parseTypeSignature("decimal(precision,scale)", ImmutableSet.of("precision", "scale"))).returnType(to).build();
return SqlScalarFunction.builder(DecimalCasts.class).signature(signature).implementation(b -> b.methods(methodNames).withExtraParameters((context) -> {
long precision = context.getLiteral("precision");
long scale = context.getLiteral("scale");
Number tenToScale;
if (isShortDecimal(context.getParameterTypes().get(0))) {
tenToScale = longTenToNth(intScale(scale));
} else {
tenToScale = bigIntegerTenToNth(intScale(scale));
}
return ImmutableList.of(precision, scale, tenToScale);
})).build();
}
Aggregations