Uploaded image for project: 'Apache Drill'
  1. Apache Drill
  2. DRILL-7421

FILTER clause for aggregate functions is ignored

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 1.16.0
    • Fix Version/s: Future
    • Component/s: None
    • Labels:
      None

      Description

      Drill ignores FILTER clause for aggregate functions.
      The following query returns the wrong result:

      select count(*), count(employee_id) filter(where employee_id < 5) from cp.`employee.json`;
      
      +--------+--------+
      | EXPR$0 | EXPR$1 |
      +--------+--------+
      | 1155 | 1155 |
      +--------+--------+
      

      Calcite already supports this feature (CALCITE-704) and as it is mentioned in the Jira ticket, such syntax is allowed by SQL standard.

      As a short solution, we should throw an exception for such queries that this functionality is not supported.
      As was mentioned in Calcite's Jira, some queries may be rewritten using switch case:

      select count(*), count(case when employee_id < 5 then employee_id else null end) from cp.`employee.json`;
      

      It is possible to add functionality into Drill to rewrite filtered aggregate calls in such a way, but some aggregate functions still would not be supported, for example, count(*).

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              volodymyr Vova Vysotskyi
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: