Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-21745

Change in join order causes query parse to fail

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 1.1.0
    • None
    • Hive
    • None

    Description

      I ran into the following case, where a query fails to parse if the join order is changed:

      create database if not exists test;
      
      drop table if exists test.table1;
      create table test.table1 (
        id string,
        col_a string
      )
      stored as textfile;
      
      drop table if exists test.table2;
      create table test.table2 (
        id string
      )
      stored as textfile;
      
      drop table if exists test.table3;
      create table test.table3 (
        col_a string,
        col_b string
      )
      stored as textfile;
      
      drop table if exists test.table4;
      create table test.table4 (
        id string
      )
      stored as textfile;
      
      -- This fails with: Invalid table alias or column reference 't3': (possible column names are: id, col_a)
      select
        1
      from
        test.table1 as t1
        left join test.table2 as t2 on t2.id = t1.id
        left join test.table3 as t3 on t1.col_a = t3.col_a
        left join test.table4 as t4 on t1.id = t4.id and t3.col_b = 'X'
      ;
      
      -- This works
      select
        1
      from
        test.table1 as t1
        left join test.table3 as t3 on t1.col_a = t3.col_a
        left join test.table4 as t4 on t1.id = t4.id and t3.col_b = 'X'
        left join test.table2 as t2 on t2.id = t1.id
      ;
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            asdaraujo Andre Araujo
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: