How to run one or more hive queries in a file using hive -f command

Hive -f command

The Hive -f command is used to execute one or more hive queries from a file in batch mode.Instead of enter into the Hive CLI and execute the queries one by one ,We can directly execute the set of queries using Hive -f option from the command line itself.

Syntax of Hive -f command

Example for Hive -f option

The test.sql file contains around 3 queries and the queries include CREATE TABLE,INSERT INTO and SELECT statement at the end of the file. The file is stored under the directory /home/Revisitclass. Here the path of the file is given in the hive -f command.

The file test.sql contains the queries as below.

Once we hit the enter after this command, it will run all the hive queries in batch mode and returns the result set in the command line itself.

Output

Related Articles : Hive -e command to run the query in Command line