Shell脚本变量接收hive语句的返回值

有时在写shell脚本时,脚本变量需要接收hive语句的返回值

#!bin/bash
sql1="
use test;
select count(1) from table_name;
"
var1=`hive -S -e "${sql1}"`

但有时,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.

有两种解决办法

  • 方法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)