Ignite版本:2.7.0。
以下是我使用的表达方式:
SUM(A1)/SUM(A2)/1000
A1、A2均为整数。
在 Ignite 中,我得到了类型 BIGINT
。
在 MySQL 中,我得到了 DECIMAL
类型。
MySQL的结果符合我的预期,因为数据确实包含十进制数字。
如果我使用下面的表达式:
SUM(A1)/SUM(A2)/1000.0
结果正确。
但是为什么 Ignite 不能派生出正确的类型呢?
最佳答案
您的问题“但是为什么 Ignite 不能派生出正确的类型?”的答案是,它确实派生出了正确的类型。 Ignite 在除法时明确应用了整数除法规则(就像 Java 那样),或者它应用了一个规则,在整数除法中产生小数位数为 0 的结果(这会产生类似的结果,尽管它可能有稍微舍入的规则)到整数除法)。
根据 SQL:2016 (ISO/IEC 9075-2:2016) 标准,这完全没问题,6.29 <数值表达式>:
Otherwise, the declared type of both operands of a dyadic arithmetic operator is exact numeric and the declared type of the result is an implementation-defined exact numeric type, with precision and scale determined as follows:
i) Let S1 and S2 be the scale of the first and second operands respectively.
ii) The precision of the result of addition and subtraction is implementation-defined, and the scale is the maximum of S1 and S2.
iii) The precision of the result of multiplication is implementation-defined, and the scale is S1 + S2.
iv) The precision and scale of the result of division are implementation-defined
请注意,这些规则中也允许 MySQL 的行为。
关于java - 为什么 "IGNITE"计算的字段返回 "BIGINT"类型?理论上应该是 "DECIMAL"类型,因为结果包含十进制数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57457986/