首页 > 其他 > 详细

将hive的hql执行结果保存到变量中

时间:2017-10-09 16:32:06      阅读:3372      评论:0      收藏:0      [点我收藏+]

这里分别针对shell脚本和python脚本举例:

 

shell脚本如下:

注意:在hive语句左右两边使用的是ESC键下面的点号,不是单引号。

#!/usr/bin/env bash

test1=`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 ${test1}`

echo --------------------
echo ${test1}

python中直接有函数os.popen(xxx).read()可以引用:

# -*-coding:utf-8-*-

import os

hqlCommand = ‘‘‘
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()
print(maxValue)
print(len(hqlCommand.strip()))

 

最后要注意的是变量的值中含有空格,需要做去空格处理。

 

将hive的hql执行结果保存到变量中

原文:http://www.cnblogs.com/30go/p/7641417.html

(0)
(6)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!