问题
I'm trying to create custom fuction for Apache Drill (v1.15).
When using a Decimal as an output data type, it fails even with the simplest example. When using another data types (int, float ..), it works well.
Is there any simple way, how to make decimals work as output of UDF?
@FunctionTemplate(
name = "testing_udf",
scope = FunctionTemplate.FunctionScope.SIMPLE,
nulls = FunctionTemplate.NullHandling.NULL_IF_NULL
)
public class TestingUdfFunction implements DrillSimpleFunc {
@Param
Decimal18Holder input;
@Output
Decimal18Holder out;
public void setup() {
}
public void eval() {
out.precision = input.precision;
out.scale = input.scale;
out.value = input.value;
}
}
SQL Call:
SELECT testing_udf(6.66);
> VALIDATION ERROR: Value 7 overflows specified precision 0 with scale 0.
回答1:
UDFs which return decimal data type should also specify returnType
in @FunctionTemplate
to be able to determine resulting scale and precision. You can use functions implementations from VarDecimalFunctions
class as an example.
来源:https://stackoverflow.com/questions/56872634/value-overflows-specified-precision-0-with-scale-0