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

physical plan in multiple Unions with jdbc storage with derived table without alias

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.6.0
    • None
    • SQL Parser, Storage - JDBC
    • None

    Description

      The problem occurs when there is more than one union in the query using jdbc storage.

      This query works:
      0: jdbc:drill:zk=local> select 0 a from (values(1))
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 1 a from (values(1))
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 2 a from (values(1));
      ----

      a

      ----

      0
      1
      2

      ----

      This query using mysql storage or mssql storage doesn't work:

      0: jdbc:drill:zk=local> select 0 as ChvOutTerc from ProcessarReceita procrec0
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 1 as ChvOutTerc from ProcessarReceita procrec1
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 2 as ChvOutTerc from ProcessarReceita procrec2;
      Error: DATA_READ ERROR: The JDBC storage plugin failed while trying setup the SQL query.

      sql SELECT *
      FROM (SELECT 0 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita"
      UNION ALL
      SELECT 1 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita")
      UNION ALL
      SELECT 2 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita"
      plugin siag_enidh
      Fragment 0:0

      [Error Id: f3afa6ce-895c-4aa3-bfda-b769e4795ae1 on hefesto.siag.pt:31010] (state=,code=0)

      Changing the physical plan to include an alias on derived table and then executing that physical plan works without problem:

      SELECT *
      FROM (SELECT 0 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita"
      UNION ALL
      SELECT 1 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita") mytable
      UNION ALL
      SELECT 2 AS "ChvOutTerc"
      FROM "dbo"."ProcessarReceita"

      Also tested with 1.7.0-SNAPSHOT (20160531) with the same results.

      Results with just one union:

      0: jdbc:drill:zk=local> select 0 as ChvOutTerc from ProcessarReceita procrec0
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 1 as ChvOutTerc from ProcessarReceita procrec1 limit 3;
      -------------

      ChvOutTerc

      -------------

      0
      0
      0

      -------------
      3 rows selected (0.708 seconds)
      0: jdbc:drill:zk=local> select 1 as ChvOutTerc from ProcessarReceita procrec1
      . . . . . . . . . . . > union all
      . . . . . . . . . . . > select 2 as ChvOutTerc from ProcessarReceita procrec2 limit 3;
      -------------

      ChvOutTerc

      -------------

      1
      1
      1

      -------------
      3 rows selected (0.449 seconds)

      Update: The query with multi unions works with Oracle jdbc driver.

      Attachments

        Activity

          People

            Unassigned Unassigned
            mlamy@siag.pt Miguel Lamy
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: