我正在使用shell脚本查询配置单元表
last_val="`hive -e "select max(id) from ${hivedatabase}.${table}"`"
echo var1="$last_val"
When the last_val = "NULL" then I want the last_val to be zero
我在下面试过了,但还是没用
function value
{
if [ "$last_val" = "NULL" ];then
echo "0"
elif [ "$last_val" != "NULL" ];then
echo "$last_val"
fi
}
echo var2="$(value)"
我想在中使用此值,以使用类似sqoop的增量导入
select * from testing.1234abc check column id > value
如何在shell脚本中实现这一点
最佳答案
我用这种方法,试试看:
#!/bin/bash
hivedatabase=mydb
table=mytable
default_value="ZERO"
last_val=$(hive -e "set hive.cli.print.header=false; select max(id) from ${hivedatabase}.${table};")
if [[ "$last_val" == "NULL" ]] ; then
last_val="$default_value"
fi
echo "$last_val"