Value overflows specified precision 0 with scale 0

怎甘沉沦 提交于 2019-12-12 22:21:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!