hive sql文件的执行方法

------------------ --------1 执行不带参数的hql文件----------------------------
hive -f 文件名.后缀

  实例:hive -f chensq_test1.hql

------------------ -----2 执行带1个普通参数的hql文件----------------------------

----- 直接在hive中执行----


 select count(*)
  from 用户名.表名 c
 where c.列名 = '01' ;

----- hql文件内容------------


 select count(*)
  from 用户名.表名 c
 where c.列名 = '${hiveconf:param1}' ;

 ---- 用命令执行文件

hive -hiveconf param1='01'  -f test_param1.hql  

----------------------3 执行带2个参数的hql文件----------------------------

----- 直接在hive中执行----
 select count(*)
  from 用户名.表名  c
 where c.列名1 = '01'
 and 列名2  = '61405'

----- hql文件内容------------

 select count(*)
  from 用户名.表名  c
 where c.列名1 = '${hiveconf:param1}'
 and 列名2  =  '${hiveconf:param2}'; 

 ---- 用命令执行文件

 hive -hiveconf param1=$'01' -hiveconf param2=$'61405'  -f  test_param2.hql

-----------参数传递实例4(执行与时间相关的hql文件):其中日期变量为日期格式

 ----- 直接在hive中执行----

select count(*)
  from 用户名.表名 c
 where c.date1 <= from_unixtime(unix_timestamp()}, 'yyyy-MM-dd HH:dd:ss')
   and c.date1 >= add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd HH:dd:ss'),-2);  

----- hql文件内容------------ 

select count(*)
  from 用户名.表名 c
 where c.date1 <= from_unixtime(unix_timestamp()}, 'yyyy-MM-dd HH:dd:ss')
   and c.date1 >= add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd HH:dd:ss'),-${hiveconf:param2});  

------用命令执行文件

 hive -hiveconf  param2=2 -f test_param3.hql

-----------参数传递实例5(执行与时间相关的hql文件):其中日期变量为字符串格式
----- 直接在hive中执行----

select count(*) 
from 用户名.表名 a 
where a.年月_col <= substr(regexp_replace(string(add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'),-1)), '-','') , 1 , 6)
and a.年月_col >= substr(regexp_replace(string(add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'),-12)), '-','') , 1 , 6);  

----- hql文件内容------------ 

select count(*) 
from 用户名.表名 a 
where a.年月_col <= substr(regexp_replace(string(add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'),-${hiveconf:param1})), '-','') , 1 , 6)
and a.年月_col >= substr(regexp_replace(string(add_months(from_unixtime(unix_timestamp(), 'yyyy-MM-dd'),-${hiveconf:param2})), '-','') , 1 , 6);  

 ---- 用命令执行文件

 hive -hiveconf param1=$1 -hiveconf param2=2  -f  test_param2.hql
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值