Apache Hive is a data warehouse infrastructure built on top of hadoop for providing data summarization, query, and analysis.
A view is a virtual table, that allows a query to be saved and treated like a table. It is a logical construct, as it does not store data like a table.
Example for view :
Create a table in hive and load the data into that table.
Create table view_table(no int,name string,salary bigint,city string,country string)row format delimited fields terminated by ‘\t’ lines terminated by ‘\n’ stored as textfile;
Load data into table :
load data local inpath ‘path/to/file’ into table tablename;
load data local inpath ‘/home/geouser/view_table.txt’ into table view_table;
View the table :
select *from view_table;
Create view :
CREATE VIEW [IF NOT EXISTS] view_name [(column_list)]
Create the query to retrieve the details of the employees living in the country usa and store the result in the view.
create view view1 as select * from view_table where country=’usa’;
View the created view table :
select no,name,city from view1;
Alter view :
alter view viewname as select_statements;
alter view view1 as select no,name from view_table where country=’usa’;
Drop the view :
drop view viewname;
drop view view1;