Enrollments closing soon for Post Graduate Certificate Program in Applied Data Science & AI By IIT Roorkee | 3 Seats Left

  Apply Now

Hive

11 / 18

Hive - Views




Not able to play video? Try with youtube

The usage of view in hive is same as that of the view in SQL. Let us understand views in hive suppose we want to find out all of 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, so select * from employees_engineering; will return all of the rows where the department is engineering. Login into CloudxLab linux console. Type hive and wait for hive prompt to appear. Use your own database run use followed by database name, here the string ${env:USER} is replaced by your username automatically, this would work only if your username is same as the name of your database. To create a view employee_engineering run command create view employee_engineering as select * from employees where department='Engineering'; to query the view run command select * from employee_engineering; in hive shell, so you can use a view as a table in your select queries while the view is representing a complex query. A view allows a query to be saved and is treated like a table, it is a logical construct as it does not store data like a table. When a query becomes long and complicated a view may be used to hide the complexity. We can divide long and complicated queries into smaller and manageable pieces called views, it is very similar to writing a function or a module in a programming language.

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...