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

Flatten functionality not well defined when we use flatten in an order by without projecting it

    XMLWordPrintableJSON

Details

    Description

      git.commit.id.abbrev=3d863b5

      Data Set :

      {
        "id" : 1,
        "lst" : [1,2,3,4]
      }
      

      The below query returns 4 rows instead of 1. The expected behavior in this case is not documented properly

      select id from `data.json` where 2 in (select flatten(lst) from `data.json`) order by flatten(lst);
      +------------+
      |     id     |
      +------------+
      | 1          |
      | 1          |
      | 1          |
      | 1          |
      +------------+
      

      The below projects a flatten.

      0: jdbc:drill:schema=dfs_eea> select id, flatten(lst) from `temp.json` where 2 in (select flatten(lst) from `temp.json`) order by flatten(lst);
      +------------+------------+
      |     id     |   EXPR$1   |
      +------------+------------+
      | 1          | 1          |
      | 1          | 2          |
      | 1          | 3          |
      | 1          | 4          |
      +------------+------------+
      

      We can agree on one of the 3 possibilites when flatten is not projected:

      1. Irrespective of whether flatten is in the select list or not, we would still return more records based on flatten in the order by
      2. Flatten in the order by clause does not change the no of records we return
      3. Using flatten in an order by (or probably group by) is not supported

      Whatever we agree on, we should document it more clearly. Let me know your thoughts

      Attachments

        Issue Links

          Activity

            People

              jaltekruse Jason Altekruse
              rkins Rahul Kumar Challapalli
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: