Hive view
Hive View
Hive :
Apache Hive is a data warehouse infrastructure built on top of hadoop for providing data summarization, query, and analysis.
View :
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.
(eg)
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 :
Syntax:
load data local inpath ‘path/to/file’ into table tablename;
(eg)
load data local inpath ‘/home/geouser/view_table.txt’ into table view_table;
View the table :
select *from view_table;
Create view :
Syntax :
CREATE VIEW [IF NOT EXISTS] view_name [(column_list)]
AS select_statement
(eg)
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 :
Syntax :
alter view viewname as select_statements;
(eg)
alter view view1 as select no,name from view_table where country=’usa’;
Drop the view :
Syntax :
drop view viewname;
(eg)
drop view view1;