Executing SQL Script file in Hive

The Hive scripts are used to collectively execute a series of SQL Commands. In other words, multiple SQL statements can be grouped and executed all at once. This helps to reduce the time and effort expended in manually drafting and executing any command. Hive supports scripting from versions of Hive 0.10.0 and beyond.

If you are looking for the same functionality in Apache Impala, please click here.

Ok, let’s see how to execute SQL files in Apache Hive.
1) Create a .sql file with set of SQL commands.
2) Save it in the local directory as shown below

impala_batch_file

3) Open HDFS terminal and enter the below command.
Hive -f /home/cloudera/sample.sql

The default location of the files is “/home/cloudera” if you are using Cloudera’s QuickStart VM. Providing full path of the file is optional if the file is already in the home (default) directory. You can use –

Hive -f sample.sql

hive batch processing

Hope you like this article. Stay in touch for more updates.

One comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s