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

Bad code generated when argument to COUNT(DISTINCT) is a GROUP BY column

    Details

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

      Description

      There is a code generation error when argument to COUNT(DISTINCT ...) is a column in the GROUP BY clause. For example,

      select count(distinct deptno) as cdd, count(*) as c
      from emp
      group by deptno
      

      generates code that is invalid (! operator applied to a long value):

                public Object current() {
                  final Object[] current = (Object[]) inputEnumerator.current();
                  return new Object[] {
                      current[0],
                      current[1],
                      !org.apache.calcite.runtime.SqlFunctions.toLong(current[1])};
                }
      

        Activity

        Hide
        julianhyde Julian Hyde added a comment -

        Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/2ddff7a5. AggregateExpandDistinctAggregatesRule was getting field offsets wrong when there was no indicator.

        Show
        julianhyde Julian Hyde added a comment - Fixed in http://git-wip-us.apache.org/repos/asf/calcite/commit/2ddff7a5 . AggregateExpandDistinctAggregatesRule was getting field offsets wrong when there was no indicator.
        Hide
        jcamachorodriguez Jesus Camacho Rodriguez added a comment -

        Resolved in release 1.13.0 (2017-06-26).

        Show
        jcamachorodriguez Jesus Camacho Rodriguez added a comment - Resolved in release 1.13.0 (2017-06-26).

          People

          • Assignee:
            julianhyde Julian Hyde
            Reporter:
            julianhyde Julian Hyde
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development