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

Scalar SUM/AVG over empty result set returns no rows instead of NULL

    XMLWordPrintableJSON

Details

    Description

      Queries below should return NULL:

      0: jdbc:drill:schema=dfs> select sum(a2) from t2 where 1=0;
      +------------+
      |   EXPR$0   |
      +------------+
      +------------+
      No rows selected (0.08 seconds)
      
      0: jdbc:drill:schema=dfs> select avg(a2) from t2 where 1=0;
      +------------+
      |   EXPR$0   |
      +------------+
      +------------+
      No rows selected (0.074 seconds)
      

      When grouped, result is correct:

      0: jdbc:drill:schema=dfs> select a2, sum(a2) from t2 where 1=0 group by a2;
      +------------+------------+
      |     a2     |   EXPR$1   |
      +------------+------------+
      +------------+------------+
      No rows selected (0.11 seconds)
      

      I'm not convinced and it is not very intuitive that correct result should be NULL, but this is what postgres returns and Aman thinks NULL is the correct behavior

      Attachments

        Issue Links

          Activity

            People

              mehant Mehant Baid
              vicky Victoria Markman
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: