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

BigDecimal underflow

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.4.0-incubating
    • None

    Description

      avg() on BigDecimal column hits SqlFunctions.divide(BigDeciaml, BigDecimal), which further calls BigDecimal.divide(BigDecimal). This method will throw exception when the result has infinite digits after the decimal point, e.g. 10/9=1.11111...

      The stack is as follows:

      java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
      	at java.math.BigDecimal.divide(BigDecimal.java:1690)
      	at org.apache.calcite.runtime.SqlFunctions.divide(SqlFunctions.java:547)
      	at Baz$5$1.current(Unknown Source)
      	at org.apache.calcite.linq4j.Linq4j$EnumeratorIterator.next(Linq4j.java:685)
      	at org.apache.calcite.avatica.util.IteratorCursor.next(IteratorCursor.java:48)
      	at org.apache.calcite.avatica.AvaticaResultSet.next(AvaticaResultSet.java:215)
      	at sqlline.IncrementalRows.hasNext(IncrementalRows.java:62)
      	at sqlline.TableOutputFormat.print(TableOutputFormat.java:33)
      	at sqlline.SqlLine.print(SqlLine.java:1652)
      	at sqlline.Commands.execute(Commands.java:833)
      	at sqlline.Commands.sql(Commands.java:732)
      	at sqlline.SqlLine.dispatch(SqlLine.java:807)
      	at sqlline.SqlLine.begin(SqlLine.java:681)
      	at sqlline.SqlLine.start(SqlLine.java:398)
      	at sqlline.SqlLine.main(SqlLine.java:292)
      

      Alternatively, divide(BigDecimal divisor, MathContext mc) should be called instead, so BigDecimal knows the precision and rounding mode to handle the infinite number.

      ---------------- Imported from GitHub ----------------
      Url: https://github.com/julianhyde/optiq/issues/280
      Created by: liyang-gmt8
      Labels:
      Created at: Mon May 12 10:25:07 CEST 2014
      State: open

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            julianhyde Julian Hyde
            github-import GitHub Import
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment