这里提供了一个示例,shell调用docker中得hive 查询数据库中每张表的数据量,例如 可以用于校验导入数据是否成功. 更便捷的方式,我可以使用pyhive 编写python脚本更方便
#! /bin/bash
# set database name or you can replace it use args
database=default
#gen query table command
qt_cmd="docker exec -it hive-server bash -c 'hive -S -e \"show tables from ${database}\" 2>/dev/null'"
echo $qt_cmd
# exec query
# eval transform str to command to excute
tables=$(eval $qt_cmd)
for tb_name in ${tables[@]}; do
# In Docker containers, the newline character used for output is \r\n,so need to fillter it.
tb_name=`echo $tb_name | grep -oP '\w+'`
# gen query table count command
cmd_sh="docker exec -it hive-server bash -c 'hive -S -e \"select count(1) from default.${tb_name}\" 2>/dev/null'"
# excute query command
cnt=$(eval $cmd_sh)
# show table name and number of rows in the table data
echo "$tb_name: $cnt"
done
0