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

Average aggregation on an Integer column throws java.lang.ClassCastException

VotersWatch issueWatchersLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

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

    Description

      There are 2 Integer columns: a, c in table abc.

      While running the following sql, it throw the ClassCastException:
      select a, avg(c) as agg from abc group by a

      Exception in thread "main" java.lang.ClassCastException: java.lang.Long incompatible with java.lang.Integer
      at org.apache.calcite.avatica.util.AbstractCursor$IntAccessor.getInt(AbstractCursor.java:460)
      at org.apache.calcite.avatica.AvaticaResultSet.getInt(AvaticaResultSet.java:311)

      The generated code that I think causing the issue, it try to cast the result to long.
      public Object current() {
      final Object[] current = (Object[]) inputEnumerator.current();
      return new Object[]

      { current[0], (long) org.apache.calcite.runtime.SqlFunctions.toInt(current[1]) / org.apache.calcite.runtime.SqlFunctions.toLong(current[2])}

      ;
      }

      Attachments

        Activity

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

          People

            julianhyde Julian Hyde
            chinwei Low Chin Wei
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment