Value overflows specified precision 0 with scale 0

2019-07-16 19:03发布

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条回答
Explosion°爆炸
2楼-- · 2019-07-16 19:46

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.

查看更多
登录 后发表回答