Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-919

ArithmeticException when querying against decimal field.

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.5.0
    • Component/s: avatica
    • Labels:
      None

      Description

      Running against Phoenix:

      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;
      

      Nets an exception on the client side:

      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)
      

      The above works without Avatica in the picture, so I'm assuming that something isn't working as it should in the Accessors.

        Issue Links

          Activity

          Hide
          elserj Josh Elser added a comment -

          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.

          Show
          elserj Josh Elser added a comment - 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.
          Show
          julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/56a612af . Josh Elser , thanks for the PR!
          Hide
          jcamachorodriguez Jesus Camacho Rodriguez added a comment -

          Resolved in release 1.5.0 (2015-11-10)

          Show
          jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.5.0 (2015-11-10)

            People

            • Assignee:
              elserj Josh Elser
              Reporter:
              elserj Josh Elser
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development