腳本tt.sh的內容如下:
#!/bin/bash
params=$1
for param in $params
do
echo $param
done
運行方式為:sh tt.sh "1 2 3 4 5"
輸出為:
所以參考上面的命令,可以把hql的腳本寫為如下方式,就可以循環執行sql:
功能:查找字符串 comments 中的param第一次出現的位置 ,返回的是位置數字
#!/bin/bash
params=$1
for param in $params
do
hive -e "insert overwrite local directory '/tmp/$param'
row format delimited fields terminated by '\t'
select locate('$param',comments) as position from tb_a;"
done
功能:查找評論中出現關鍵字的內容,沒有關鍵詞的內容過濾掉
#!/bin/bash
params=$1
for param in $params
do
hive -e "insert overwrite local directory '/tmp/$param'
row format delimited fields terminated by '\t'
select position from
(select locate('$param',comments) as position from tb_a where position != '0') a
where a.position !='0' ;"
done
以上這篇shell中循環調用hive sql 腳本的方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- python處理數據,存進hive表的方法
- python導出hive數據表的schema實例代碼
- php ZipArchive實現多文件打包下載實例
- sql server編寫archive通用模板腳本實現自動分批刪除數據
- mysql 5.7.18 Archive壓縮版安裝教程
- mysql 5.7 zip archive版本安裝教程
- 使用shell腳本執行hive、sqoop命令的方法
- hive-shell批量命令執行腳本的實現方法
- 如何在python中寫hive腳本