HIVE:

Hive is a data warehouse infrastructure built on top of Hadoop for providing data summarization, query, and analysis.

SCRIPT:

Hive scripts are used to execute a set of Hive commands collectively. This is used for reducing time and effort invested in writing and executing each command manually.

Creating a Hive Script and run multiple commands

Step-1

First Open the notepad or any text editor

Step-2

Writing the script (Multiple commands) and save it as .sql file

Save the following script as named Employee.sql
hive,script file in hive,script file hive

Step-3

Open a terminal
ctrl+Alt+t

Step-4

Run the script

hive -f <path of the script file>

hive -f /home/geouser/Documents/Employee.sql

hive,script file in hive,script file hive

Step-5

Output

hive,script file in hive,script file hive

hive,script file in hive,script file hive

hive,script file in hive,script file hive

Description about commands:

Drop table Employee_details;

-> Drop the table if already exist,

create table Employee_details (e_no varchar(20), e_name string, e_salary int, role string) row format delimited fields terminated by ‘,’ lines terminated by ‘\n’;

-> Create a table named as Employee_details with 4 columns (e_no,e_name,e_salary,role)

load data local inpath ‘/home/geouser/Documents/employee_details’ into table Employee_details;

-> Load the datas from local file (employee_details) to Hive table (Employee_details)

employee_details (data stored in local)

hive,script file in hive,script file hive

insert into Employee_details values (‘EM160DA05’,’Andrason ‘,1000000,’Data Analyst’),(‘EM160DA06′,’Alaisbrist’,1005000,’Data Analyst’);

-> Insert the value to the Employee_details table using Insert command

select * from Employee_details;

-> Select the all data from the Employee_details table

hive,script file in hive,script file hive

select e_no,e_name,e_salary,role from Employee_details order by (e_no);

-> Select all the data from the Employee_details table with order

hive,script file in hive,script file hive

select e_no, e_salary from Employee_details;

-> Select specific columns from the Employee_details table

hive,script file in hive,script file hive

select * from Employee_details where e_salary > 1000000;

-> Select the data based on the condition from the table Employee_detail

hive,script file in hive,script file hive

select e_no,e_name,role from Employee_details where e_salary > 1000000 AND e_salary < 2000000;

-> Select the data based on the condition from the Employee_details table

hive,script file in hive,script file hive