shell脚本中变量接受hive语句的返回值问题

问题

20190916


有时在写shell脚本时,脚本变量可以接受hive语句的返回值

#!bin/bash
sql1="
use mydatabase;
select min(colmun) from table_name;
"
var1=`hive -S -e "${sql1}"`
sql2="
use  mydatabase;
select cast(1 as tinyint) as flag;
"
var2=`hive -S -e "${sql2}"`

但有时,hive -S -e "sql"语句执行完后,有时候执行会包含 WARN开头的日志:
WARN: The method class org.apache.commons.logging.impl.SLF4JLogFactory#release() was invoked.
WARN: Please see http://www.slf4j.org/codes.html#release for an explanation.
此时变量var接受的返回值里含有这几行WARN...语句,下面几种解决方法。\

  • 方法1
var=`hive -e "${sql}" | grep -v "WARN"`
  • 方法2
  • 添加 export HIVE_SKIP_SPARK_ASSEMBLY=true; 到 /etc/profile
echo “export HIVE_SKIP_SPARK_ASSEMBLY=true;>> /etc/profile
source /etc/profile

参考

hive -e "sql"重定向
hive -e "sql"WARN
shell grep命令和正则表达

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值