Reader small image

You're reading from  Apache Hive Essentials

Product typeBook
Published inFeb 2015
Reading LevelIntermediate
PublisherPackt
ISBN-139781783558575
Edition1st Edition
Languages
Right arrow
Author (1)
Dayong Du
Dayong Du
author image
Dayong Du

Dayong Du has all his career dedicated to enterprise data and analytics for more than 10 years, especially on enterprise use case with open source big data technology, such as Hadoop, Hive, HBase, Spark, etc. Dayong is a big data practitioner as well as author and coach. He has published the 1st and 2nd edition of Apache Hive Essential and coached lots of people who are interested to learn and use big data technology. In addition, he is a seasonal blogger, contributor, and advisor for big data start-ups, co-founder of Toronto big data professional association.
Read more about Dayong Du

Right arrow

Set operation – UNION ALL


To operate the result set vertically, Hive only supports UNION ALL right now. And, the result set of UNION ALL keeps duplicates if any. Before Hive 0.13.0, UNION ALL can only be used in the subquery. Since Hive 0.13.0, UNION ALL can also be used in top-level queries. The following are examples of the UNION ALL statements:

  • Check the name column in the employee_hr and employee table:

    jdbc:hive2://> SELECT name FROM employee_hr;
    +----------+
    |   name   |
    +----------+
    | Michael  |
    | Will     |
    | Steven   |
    | Lucy     |
    +----------+
    4 rows selected (0.116 seconds)
    
    jdbc:hive2://> SELECT name FROM employee;
    +----------+
    |   name   |
    +----------+
    | Michael  |
    | Will     |
    | Shelley  |
    | Lucy     |
    +----------+
    4 rows selected (0.049 seconds)
    
  • Use UNION on the name column from both tables, including duplications:

    jdbc:hive2://> SELECT a.name 
    . . . . . . .> FROM employee a
    . . . . . . .> UNION ALL
    . . . . . . .> SELECT b.name 
    . . . . . . .> FROM employee_hr...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Apache Hive Essentials
Published in: Feb 2015Publisher: PacktISBN-13: 9781783558575

Author (1)

author image
Dayong Du

Dayong Du has all his career dedicated to enterprise data and analytics for more than 10 years, especially on enterprise use case with open source big data technology, such as Hadoop, Hive, HBase, Spark, etc. Dayong is a big data practitioner as well as author and coach. He has published the 1st and 2nd edition of Apache Hive Essential and coached lots of people who are interested to learn and use big data technology. In addition, he is a seasonal blogger, contributor, and advisor for big data start-ups, co-founder of Toronto big data professional association.
Read more about Dayong Du