hive使用小技巧-如何往Hive SQL中传入参数

很多SQL需要重复执行,可能是每天执行一次,而需要修改的只是SQL中的日期字段,这种情况下可以使用 参数代入
使用的方式
  1. hive -d key1=value1 -d key2=value -d key3=value3 ...
复制代码

例子-1:

  1. hive -d shell_date_1='20120425' -d shell_date_2='20120426'
  2. hive> set shell_date_1;
  3. shell_date_1=20120425
  4. hive> set shell_date_2;
  5. shell_date_2=20120426
  6. hive> explain select * from dual where user_id = ${shell_date_1};
复制代码

这里面的 shell_date_1 会替换为 20120425
例子-2:
  1. hive -d shell_date_1='20120425' -d shell_date_2='20120426' \ 
  2.        -e "explain select * from dual where user_id = ${shell_date_1}"
复制代码

例子-3:
  1. vim hive.sql
复制代码

内容为:

  1. explain select * from dual where user_id = ${shell_date_1}
  2. hive -d shell_date_1='20120425' -f hive.sql
复制代码

转载于:https://www.cnblogs.com/java20130722/archive/2013/05/02/3206939.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值