You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Josh Elser (JIRA)" <ji...@apache.org> on 2015/10/13 19:31:05 UTC

[jira] [Commented] (CALCITE-919) ArithmeticException when querying against decimal field.

    [ https://issues.apache.org/jira/browse/CALCITE-919?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14955315#comment-14955315 ] 

Josh Elser commented on CALCITE-919:
------------------------------------

In practice, for a table with a value of {{13.7}}, we end up with a Number on the client side which is a BigDecimal, implemented as {{137}} with a scale of {{1}} and precision of {{3}}.

It looks like when we call {{setScale}}, the fact that we were calling this method with a new scale of {{0}}, it caused some confusion and we got this exception instead.

> ArithmeticException when querying against decimal field.
> --------------------------------------------------------
>
>                 Key: CALCITE-919
>                 URL: https://issues.apache.org/jira/browse/CALCITE-919
>             Project: Calcite
>          Issue Type: Bug
>          Components: avatica
>            Reporter: Josh Elser
>            Assignee: Josh Elser
>             Fix For: 1.5.0-incubating
>
>
> Running against Phoenix:
> {code}
> DROP TABLE IF EXISTS foo;
> CREATE TABLE IF NOT EXISTS foo (ID INTEGER PRIMARY KEY,decimal_id DECIMAL);
> UPSERT INTO foo VALUES (0,13.7);
> UPSERT INTO foo VALUES (1,13.7);
> UPSERT INTO foo VALUES (2,13.7);
> SELECT * FROM foo;
> {code}
> Nets an exception on the client side:
> {code}
> java.lang.ArithmeticException: Rounding necessary
> 	at java.math.BigDecimal.divideAndRound(BigDecimal.java:1452)
> 	at java.math.BigDecimal.setScale(BigDecimal.java:2402)
> 	at org.apache.calcite.avatica.util.AbstractCursor$NumberAccessor.getBigDecimal(AbstractCursor.java:704)
> 	at org.apache.calcite.avatica.util.AbstractCursor$NumberAccessor.getBigDecimal(AbstractCursor.java:708)
> 	at org.apache.calcite.avatica.AvaticaSite.get(AvaticaSite.java:327)
> 	at org.apache.calcite.avatica.AvaticaResultSet.getObject(AvaticaResultSet.java:381)
> 	at sqlline.Rows$Row.<init>(Rows.java:157)
> 	at sqlline.IncrementalRows.hasNext(IncrementalRows.java:63)
> 	at sqlline.TableOutputFormat.print(TableOutputFormat.java:33)
> 	at sqlline.SqlLine.print(SqlLine.java:1653)
> 	at sqlline.Commands.execute(Commands.java:833)
> 	at sqlline.Commands.sql(Commands.java:732)
> 	at sqlline.SqlLine.dispatch(SqlLine.java:808)
> 	at sqlline.SqlLine.begin(SqlLine.java:681)
> 	at sqlline.SqlLine.start(SqlLine.java:398)
> 	at sqlline.SqlLine.main(SqlLine.java:292)
> {code}
> The above works without Avatica in the picture, so I'm assuming that something isn't working as it should in the Accessors.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)