這裡分別針對shell指令碼和python指令碼舉例:
shell指令碼如下:
注意:在hive語句左右兩邊使用的是esc鍵下面的點號,不是單引號。
#!/usr/bin/envbashtest1=`hive -s -e "
select max(period_value) from dw_dm.dm_guba_loginlog_activity_stat where dim = 'all' and period = 'day' and year = '2017';"`
test1=`echo
$`echo
'--------------------
'echo $
python中直接有函式os.popen(***).read()可以引用:
#-*-coding:utf-8-*-
import
oshqlcommand = '''
hive -s -e "select max(period_value) from dw_dm.dm_guba_loginlog_activity_stat
where dim = 'all'
and period = 'day'
and year = '2017';"
'''maxvalue =os.popen(hqlcommand).read()
(maxvalue)
print(len(hqlcommand.strip()))
最後要注意的是變數的值中含有空格,需要做去空格處理。
利用python將hive查詢結果儲存到mysql
python指令碼連線hive獲取返回值 此指令碼支援add jar file 使用者hive查詢結果的返回值更新mysql指定表指定字段 def mysqlexe sql conn mysqldb.connect host 10.10.111.111 user user passwd passwo...
php連線hive執行HQL查詢
使用php連線hive的條件 1 需要安裝thrift 安裝步驟 configure without ruby make make install 如果沒有安裝libevent libevent devel的應該先安裝這兩個依賴庫yum y install libevent libevent dev...
將MySQL中sql執行結果儲存到檔案
有兩種方法。方法一 在mysql 提示符中使用tee mysql tee output.txt logging to file output.txt mysql notee outfile disabled.或者mysql t output.txt logging to file output.tx...