Hive - Views






Important Note - We recommend you to execute the given commands on Hive Console instead of Hue. The video is only for representational purposes.

The usage of view in Hive is the same as that of the view in SQL. Let's understand views in Hive. Suppose, we want to find out all the employees in the engineering department. The usual way is to write Hive query SELECT * FROM employees where department='Engineering';. We can create a view employees_engineering for the above query.

This view employees_engineering is a shortcut to the whole query. select * from employees_engineering will return all the rows where the department is Engineering.

Type the command displayed on the screen to create employees_engineering view. Now we can query from the view to get records instead of the table.

INSTRUCTIONS

Steps:

  • Run command hive in the web console to launch Hive. Run below command in Hive.
  • To create a view employee_engineering,

    CREATE VIEW employee_engineering as
    SELECT * FROM employees where department = 'Engineering' ;
    
  • To query from the view, run below command in Hive shell

    SELECT * FROM employee_engineering;
    

Loading comments...