OK, I think I know why... our number is a result of a division, and:

    /** Finds the result type of a decimal division operation. */
>     public static DecimalType findDivisionDecimalType(
>             int precision1, int scale1, int precision2, int scale2) {
>         // adopted from
>         //
> https://docs.microsoft.com/en-us/sql/t-sql/data-types/precision-scale-and-length-transact-sql
>         int scale = Math.max(6, scale1 + precision2 + 1);
>         int precision = precision1 - scale1 + scale2 + scale;
>         if (precision > DecimalType.MAX_PRECISION) {
>             scale = Math.max(6, DecimalType.MAX_PRECISION - (precision -
> scale));
>             precision = DecimalType.MAX_PRECISION;
>         }
>         return new DecimalType(false, precision, scale);
>     }
>

So the result has a max scale of  6......

Boot <331233...@qq.com> 于2021年8月2日周一 下午5:46写道:

> I meet a similar issue that is the cast(decimal) function can not transfer
> the number to an expected precision in table API such as
> select(expressions). For transferring String to Expression I use the flink
> built-in function of parseExpression defined in ExpressionParser class.
> ---Original---
> *From:* "LIU Xiao"<liuxiaogen...@gmail.com>
> *Date:* Mon, Aug 2, 2021 17:29 PM
> *To:* "user"<user@flink.apache.org>;
> *Subject:* How can I customize (BigDecimal) MathContext of
> flink-table-planner-blink?
>
> After upgrade Flink from 1.6 to 1.13 (flink-table-planner-blink), the
> result of our program changed:
> before: 10.38288597, after: 10.38288600
>
> We used to use "tableEnv.config().setDecimalContext(new
> MathContext(MathContext.DECIMAL128.getPrecision(), RoundingMode.DOWN))"
> with Flink 1.6, but flink-table-planner-blink seems to just ignore the
> config and use RoundingMode.HALF_UP and maybe DECIMAL(38, 18) is alose not
> enough for us.
>

Reply via email to