hive参数传递hivevar、hiveconf

hiveconf 和 hivevar

1、传递单个参数

1)hiveconf

  • hiveconf用于定义hive执行时的属性,即配置参数

  • 可覆盖hive-site.xml (hive-default.xml)中的参数值,如用户执行目录、日志打印级别、执行队列等

    常用的配置属性如下:

    参数名称参数含义
    hive.metastore.warehouse.dir启动时指定用户目录
    hive.cli.print.current.db显示当前数据库
    hive.root.logger输出日志信息
    hive.cli.print.header显示列名称
    mapred.job.queue.name执行队列名称

    当然,配置属性一般会通过set命令进行设置!
    比如

    set hive.merge.mapfiles = true;
    

    其等价于

    hive --hiveconf "hive.merge.mapfiles=true"
    

2)hivevar

  • hivevar用于定义hive运行时的变量替换

  • 通过这个选项可以为变量赋值

    比如

    # 1.执行单个sql语句,使用'hive -e'
    hive --hivevar curr_date='20191001' -e 'select * from com_access_info where p_date_sttc = ${curr_date} limit 10;'
    
    # 2.执行sql脚本,使用'hive -f'
    hive --hivevar curr_date='20191001' -f ./test.sql
    

    其中test.sql如下

    select * from com_access_info where p_date_sttc = ${curr_date} limit 10;
    

2、传递多个参数

1)hiveconf

2)hivevar

有一天,突然心血来潮,想在sql脚本中指定多个变量,以便使脚本能够更灵活的使用。

需求:获取指定时间段内的访客记录
get_visitor_record_between.sql

select * from com_access_info where p_date_sttc > ${start_date} and p_date_sttc <= ${end_date};

通过如下命令执行

hive --hivevar start_date='20190915' --hivevar end_date='20191001' -f ./get_visitor_record_between.sql

即在每个变量前都指定hivevar限定!!

搞定!

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值