gpt4 book ai didi

hive - 您可以有条件地使 Hive 脚本失败吗?

转载 作者:行者123 更新时间:2023-12-02 20:46:43 24 4
gpt4 key购买 nike

我想有条件地使配置单元脚本失败。就像如果某个表中没有数据一样,脚本应该失败,否则继续。我知道这可能不是理想的解决方案,但出于某种原因这是我的要求。由于 HQL 不是过程语言,因此这是一个挑战。

最佳答案

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$

关于hive - 您可以有条件地使 Hive 脚本失败吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44122731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com