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

UNION ALL with ORDER BY fails when column aliases don't match

    XMLWordPrintableJSON

Details

    Description

      The following query fails to execute:

      SELECT x
      FROM
      (SELECT Sum(ss_ext_sales_price) x
      FROM  store_sales
      UNION ALL
      SELECT Sum(cs_ext_sales_price) y
      FROM catalog_sales) tmp
      ORDER BY x;
      
      SELECT x
      FROM
      (SELECT ss_ext_sales_price x
      FROM  store_sales
      UNION ALL
      SELECT cs_ext_sales_price y
      FROM catalog_sales) tmp
      ORDER BY x;
      
      SELECT x
      FROM
      (SELECT ss_ext_sales_price x
      FROM  store_sales
      UNION ALL
      SELECT ss_ext_sales_price y
      FROM store_sales) tmp
      ORDER BY x;
      
      Error from Drill:
      Query failed: RemoteRpcException: Failure while running fragment., Sort doesn't currently support sorts with changing schemas. 
      java.lang.RuntimeException: java.sql.SQLException: Failure while executing query.
      ...
      

      Log snippet attached.

      Changing the alias from 'y' to 'x' in the second sub-query will solve the issue.

      Attachments

        1. drillbit.log
          10 kB
          Abhishek Girish

        Issue Links

          Activity

            People

              seanhychu Sean Hsuan-Yi Chu
              agirish Abhishek Girish
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: