You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Jesus Camacho Rodriguez (JIRA)" <ji...@apache.org> on 2016/08/05 07:19:20 UTC
[jira] [Resolved] (CALCITE-1344) Incorrect inferred precision when
BigDecimal value is less than 1
[ https://issues.apache.org/jira/browse/CALCITE-1344?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Jesus Camacho Rodriguez resolved CALCITE-1344.
----------------------------------------------
Resolution: Fixed
Fix Version/s: 1.9.0
Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/39baed5 . Thanks for reviewing [~julianhyde]
> Incorrect inferred precision when BigDecimal value is less than 1
> -----------------------------------------------------------------
>
> Key: CALCITE-1344
> URL: https://issues.apache.org/jira/browse/CALCITE-1344
> Project: Calcite
> Issue Type: Bug
> Affects Versions: 1.8.0
> Reporter: Jesus Camacho Rodriguez
> Assignee: Jesus Camacho Rodriguez
> Fix For: 1.9.0
>
>
> Method {{makeExactLiteral(BigDecimal)}} in RexBuilder infers the incorrect precision when decimal < 1 e.g. for 0.06 it infers the type to be Decimal(1,2) instead of Decimal(3,2).
> {code:java}
> /**
> * Creates a numeric literal.
> */
> public RexLiteral makeExactLiteral(BigDecimal bd) {
> RelDataType relType;
> int scale = bd.scale();
> long l = bd.unscaledValue().longValue();
> assert scale >= 0;
> assert scale <= typeFactory.getTypeSystem().getMaxNumericScale() : scale;
> assert BigDecimal.valueOf(l, scale).equals(bd);
> if (scale == 0) {
> if ((l >= Integer.MIN_VALUE) && (l <= Integer.MAX_VALUE)) {
> relType = typeFactory.createSqlType(SqlTypeName.INTEGER);
> } else {
> relType = typeFactory.createSqlType(SqlTypeName.BIGINT);
> }
> } else {
> int precision = bd.unscaledValue().abs().toString().length();
> relType =
> typeFactory.createSqlType(SqlTypeName.DECIMAL, precision, scale);
> }
> return makeExactLiteral(bd, relType);
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)