腳本tt.sh的內(nèi)容如下:
#!/bin/bash
params=$1
for param in $params
do
echo $param
done
運(yùn)行方式為:sh tt.sh "1 2 3 4 5"
輸出為:
所以參考上面的命令,可以把hql的腳本寫為如下方式,就可以循環(huán)執(zhí)行sql:
功能:查找字符串 comments 中的param第一次出現(xiàn)的位置 ,返回的是位置數(shù)字
#!/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
功能:查找評論中出現(xiàn)關(guān)鍵字的內(nèi)容,沒有關(guān)鍵詞的內(nèi)容過濾掉
#!/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中循環(huán)調(diào)用hive sql 腳本的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- python處理數(shù)據(jù),存進(jìn)hive表的方法
- python導(dǎo)出hive數(shù)據(jù)表的schema實例代碼
- php ZipArchive實現(xiàn)多文件打包下載實例
- sql server編寫archive通用模板腳本實現(xiàn)自動分批刪除數(shù)據(jù)
- mysql 5.7.18 Archive壓縮版安裝教程
- mysql 5.7 zip archive版本安裝教程
- 使用shell腳本執(zhí)行hive、sqoop命令的方法
- hive-shell批量命令執(zhí)行腳本的實現(xiàn)方法
- 如何在python中寫hive腳本