点燃十进制数据类型问题

Ignite Decimal Datatype issue

我在 apache ignite 中创建了 table,如下所示。

创建table测试(id号,值小数(4,1),主键(id)

因此值列的精度应为 4,小数位数应为 1。因此,无论我将插入 table 中的任何数据(如 1234.1234),它都应 trim 为 1234.1。因为我对列值的 table 定义是 decimal(4,1).

但它没有按预期工作。

我使用的是 apache ignite 版本 2.7.5。

如果我做错了什么,请告诉我。

插入时需要声明value为decimal(5,1)并使用round函数

插入测试(1, round(1234.1234,1))

https://apacheignite-sql.readme.io/docs/round


在你的例子中:

Ignite 将 1234.1234 转换为 BigDecimal 并根据指定的精度进行验证。

此处 prop.precision() 等于 4 而 prop.scale() 等于 1

               BigDecimal dec = (BigDecimal)propVal;  //propVal is the value i.e. 1234.1234 in your case

                if (dec.precision() > prop.precision()) { //prop are the precisions you specified i.e. (4,1)  in your case
                    throw new IgniteSQLException("Value for a column '" + prop.name() + "' is out of range. " +
                        "Maximum precision: " + prop.precision() + ", actual precision: " + dec.precision(),
                        isKey ? TOO_LONG_KEY : TOO_LONG_VALUE);
                }
                else if (prop.scale() != -1 &&
                    dec.scale() > prop.scale()) {
                    throw new IgniteSQLException("Value for a column '" + prop.name() + "' is out of range. " +
                        "Maximum scale : " + prop.scale() + ", actual scale: " + dec.scale(),
                        isKey ? KEY_SCALE_OUT_OF_RANGE : VALUE_SCALE_OUT_OF_RANGE);
                }