You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Vladimir Sitnikov (JIRA)" <ji...@apache.org> on 2015/01/30 10:28:35 UTC

[jira] [Commented] (CALCITE-580) Average aggregation on an Integer column throw java.lang.ClassCastException

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

Vladimir Sitnikov commented on CALCITE-580:
-------------------------------------------

Offending code is in {{org.apache.calcite.adapter.enumerable.JavaRowFormat#record}}:

{code:java}
    public Expression record(Type javaRowClass, List<Expression> expressions) {
      return Expressions.newArrayInit(
          Object.class, stripCasts(expressions)); // stripCasts kills {{(int)}} cast.
    }
{code}



> Average aggregation on an Integer column throw java.lang.ClassCastException
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-580
>                 URL: https://issues.apache.org/jira/browse/CALCITE-580
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Low Chin Wei
>            Assignee: Julian Hyde
>
> 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])};
> }



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