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

window functions give different results if star is used in inner query

    XMLWordPrintableJSON

Details

    Description

      The following queries give different results, although they are similar:

      SELECT position_id, COUNT(*) OVER w AS `count` FROM (SELECT position_id FROM `/b1p2tbl` ORDER BY employee_id, sub) WINDOW w AS (PARTITION BY position_id);
      +--------------+--------+
      | position_id  | count  |
      +--------------+--------+
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 1            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      | 2            | 10     |
      +--------------+--------+
      
      SELECT position_id, COUNT(*) OVER w AS `count` FROM (SELECT * FROM dfs.data.`b1p2tbl` ORDER BY employee_id, sub) WINDOW w AS (PARTITION BY position_id);
      +--------------+--------+
      | position_id  | count  |
      +--------------+--------+
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 1            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      | 2            | 20     |
      +--------------+--------+
      

      the results of the second query are incorrect.

      Attachments

        1. b1p1tbl.json
          1 kB
          Abdel Hakim Deneche

        Activity

          People

            Unassigned Unassigned
            adeneche Abdel Hakim Deneche
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: