Creating and populating Hive tables and views using Hive query results

Hive allows us to save the output data of Hive queries by creating new Hive tables. We can also insert the resultant data of a Hive query into another existing table as well.

Getting ready

Install Hive and follow the Creating databases and tables using Hive CLI recipe.

How to do it...

The following steps show you how to store the result of a Hive query into a new Hive table:

  1. Issue the following query to save the output of the query of step 3 of the preceding recipe to a table named tmp_users:
    hive> CREATE TABLE tmp_users AS SELECT user_id, location, age FROM users WHERE age>18 and age <34;
    
    Table bookcrossing.tmp_users stats: [num_partitions: 0, num_files: 1, num_rows: 0, total_size: ...

Get Hadoop MapReduce v2 Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.