You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Mihai Budiu (Jira)" <ji...@apache.org> on 2024/12/16 21:45:00 UTC
[jira] [Assigned] (CALCITE-6733) Type inferred by coercion for comparisons with decimal is too narrow
[ https://issues.apache.org/jira/browse/CALCITE-6733?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Mihai Budiu reassigned CALCITE-6733:
------------------------------------
Assignee: Mihai Budiu
> Type inferred by coercion for comparisons with decimal is too narrow
> --------------------------------------------------------------------
>
> Key: CALCITE-6733
> URL: https://issues.apache.org/jira/browse/CALCITE-6733
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.38.0
> Reporter: Mihai Budiu
> Assignee: Mihai Budiu
> Priority: Minor
>
> The following statement fails at runtime:
> {code}
> SELECT ASCII('8') >= ABS(1.1806236821);
> {code}
> with the exception:
> {code}
> java.lang.ArithmeticException: Value 56 cannot be represented as a DECIMAL(11, 10)
> at org.apache.calcite.linq4j.tree.Primitive.checkOverflow(Primitive.java:410)
> at org.apache.calcite.linq4j.tree.Primitive.integerDecimalCast(Primitive.java:515)
> {code}
> I have introduced this bug when reworking the type coercion.
> The cause is an incorrect derivation of precision/scale in the common type used for comparisons;
> {code}
> RelDataType result =
> factory.createSqlType(type2.getSqlTypeName(),
> Math.max(type1.getPrecision(), type2.getPrecision()), type2.getScale());
> {code}
> This is wrong, because the precision is the total number of digits, and not the number of digits before the decimal point. The precision is derived is not sufficient to store the integer number.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)