我想有条件地失败一个配置单元脚本。就像某个表中没有数据一样,脚本应该失败,否则继续。我知道这可能不是理想的解决方案,但出于某种原因这是我的要求。由于HQL不是程序语言,因此是一项挑战。
答案 0 :(得分:2)
<强> ASSERT_TRUE 强>
hive> select assert_true (2>1);
OK
NULL
Time taken: 2.61 seconds, Fetched: 1 row(s)
hive> select assert_true (2<1);
OK
Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: ASSERT_TRUE(): assertion failed.
Time taken: 1.063 seconds
hive>
<强>演示强>
myscript.sql
set hive.cli.errors.ignore=false; -- this is the default
select 'checkpoint 1';
drop table t1;
create table t1 as select 1;
select assert_true(count(*)>0) from t1;
select 'checkpoint 2';
drop table t2;
create table t2 as select 2 where false;
select assert_true(count(*)>0) from t2;
select 'checkpoint 3';
drop table t3;
create table t3 as select 3;
select assert_true(count(*)>0) from t3;
select 'checkpoint 4';
bash-4.1$ hive -f myscript.sql 2>/dev/null
checkpoint 1
NULL
checkpoint 2
bash-4.1$