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限定!!
搞定!