Hive on Error Stop Script Execution – Options

  • Post author:
  • Post last modified:November 2, 2019
  • Post category:BigData
  • Reading time:6 mins read

When you build a data warehouse on top of Hadoop HDFS using Hive framework, you may have to execute HiveQL or SQL queries or HiveQL script containing a bunch of HiveQL statements. Hive and Beeline does provide option to execute a script file. There may be a scenario in which you may want to stop the script execution in case if any of the SQL statement fails. In this article, we will check stop script execution on error in Hive. We shall see both Hive and Beeline CLI options to exit script execution in case if error occurred.

Hive on Error Stop Script Execution

There are two option you can use to connect to Hive server: Using Hive command line interface and Beeline command line interface (CLI).

Both CLI provides an option to continue and stop script execution in case if any errors in any of the HiveQL statements.

Following are the Hive on error stop options:

  • Hive hive.cli.errors.ignore option
  • Beeline –force Option

Now let us check these options with an examples

Hive hive.cli.errors.ignore option to Stop Script Execution

The hive.cli.errors.ignore is a Hive shell parameter with values True/False. When set True, it will continue script execution if one of the SQL statement fails, otherwise when set to False, Hive CLI will stop execution by returning error code 1.

Test Script

We have created test script with three tables. In the script, test1 and test2 tables are present. Test table is not present.

select * from test1;

select * from test;

select * from test2;

For examples, consider below example with hive.cli.errors.ignore option set to False.

hive --hiveconf hive.cli.errors.ignore=false -f /home/cloudera/test_hql.hql

Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
OK
1
2
Time taken: 3.176 seconds, Fetched: 2 row(s)
FAILED: SemanticException [Error 10001]: Line 3:14 Table not found 'test'

And consider below example with hive.cli.errors.ignore option set to True.

hive --hiveconf hive.cli.errors.ignore=true -f /home/cloudera/test_hql.hql

Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
OK
1
2
Time taken: 2.734 seconds, Fetched: 2 row(s)
FAILED: SemanticException [Error 10001]: Line 3:14 Table not found 'test'
OK
3
4
Time taken: 0.188 seconds, Fetched: 2 row(s)

Related Article

Beeline force Option to Stop Script Execution on Error

Similar to Hive CLI, Beeline CLI provides –force to continue script execution if one of the SQL statement fails, otherwise it will stop execution with an error.

For example, consider below example with –force option.

$ beeline -u jdbc:hive2://localhost:10000/default -n cloudera -p cloudera --force -f /home/cloudera/test_hql.hql
...
0: jdbc:hive2://localhost:10000/default> select * from test1;
...
INFO  : OK
+-------------+--+
| test1.col1  |
+-------------+--+
| 1           |
| 2           |
+-------------+--+
2 rows selected (0.967 seconds)

Error: Error while compiling statement: FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'test' (state=42S02,code=10001)
...
+-------------+--+
| test2.col1  |
+-------------+--+
| 3           |
| 4           |
+-------------+--+
2 rows selected (0.407 seconds)

And consider below example without –force option.

]$ beeline -u jdbc:hive2://localhost:10000/default -n cloudera -p cloudera -f /home/cloudera/test_hql.hql
...
0: jdbc:hive2://localhost:10000/default> select * from test1;
...
+-------------+--+
| test1.col1  |
+-------------+--+
| 1           |
| 2           |
+-------------+--+
2 rows selected (0.787 seconds)

0: jdbc:hive2://localhost:10000/default> select * from test;
Error: Error while compiling statement: FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'test' (state=42S02,code=10001)

Related Article

Hope this helps 🙂