@Test
  public void testUnionView() throws Exception {
    String prefix = "tunionview" + NAME_PREFIX;
    final String tab1 = prefix + "t1";
    final String tab2 = prefix + "t2";
    final String view1 = prefix + "v1";
    driver.run("create table " + tab1 + "(id int)");
    driver.run("create table " + tab2 + "(id int)");
    driver.run("create view " + view1 + " as select t.id from "
            + "(select " + tab1 + ".id from " + tab1 + " union all select " + tab2 + ".id from " + tab2 + ") as t");

    driver.compile("select * from " + view1, true);
    // view entity
    assertEquals("default@" + view1, CheckInputReadEntity.readEntities[0].getName());

    // first table in union query with view as parent
    assertEquals("default@" + tab1, CheckInputReadEntity.readEntities[1].getName());
    assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[1].isDirect());
    assertEquals("default@" + view1, CheckInputReadEntity.readEntities[1]
        .getParents()
        .iterator().next().getName());
    // second table in union query with view as parent
    assertEquals("default@" + tab2, CheckInputReadEntity.readEntities[2].getName());
    assertFalse("Table is not direct input", CheckInputReadEntity.readEntities[2].isDirect());
    assertEquals("default@" + view1, CheckInputReadEntity.readEntities[2]
        .getParents()
        .iterator().next().getName());

  }
Verify that the parent entities are captured correctly for union views
@throws Exception
ql/src/test/org/apache/hadoop/hive/ql/plan/TestViewEntity.java