本文主要讨论的应用场景是:
通常Hive ETL工程师,写好HQL语句后,是一个文件,如何把文件组织起来整体运行呢?
这时就需要一个工具来工程化地执行HQL文件。
根据ETL的特性,想了下目前需要提供的功能列举如下:
1.传参
2.写代码注释
3.自定义hiveconf(set xxx=xxx)
Hive提供的service比较多,具体可以通过hive --help(注意不是hive -h),这里主要针对Cli(也是default service)进行,
我们使用hive --service cli -h来看看以上功能是否可以得到解决
二、测试自定义设置有效
三、测试注释 设置有效,支持'--'注释方法,但是不支持'#'(如果不是处女座,似乎也就够了。。。)
如上,我们就可以实现对HQL脚本的工程化执行了(当然外面可以包装一个脚本,实现对常用参数的配置),然后配合调度系统进行调度执行。
通常Hive ETL工程师,写好HQL语句后,是一个文件,如何把文件组织起来整体运行呢?
这时就需要一个工具来工程化地执行HQL文件。
根据ETL的特性,想了下目前需要提供的功能列举如下:
1.传参
2.写代码注释
3.自定义hiveconf(set xxx=xxx)
Hive提供的service比较多,具体可以通过hive --help(注意不是hive -h),这里主要针对Cli(也是default service)进行,
我们使用hive --service cli -h来看看以上功能是否可以得到解决
[dcli@gd6g12s146-hadoop-namenode2 sql]$ hive --service cli -h
Missing argument for option: h
usage: hive
-d,--define <key=value> Variable subsitution to apply to hive
commands. e.g. -d A=B or --define A=B
--database <databasename> Specify the database to use
-e <quoted-query-string> SQL from command line
-f <filename> SQL from files
-H,--help Print help information
-h <hostname> connecting to Hive Server on remote host
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable subsitution to apply to hive commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-p <port> connecting to Hive Server on port number
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the console)
尝试使用hive自带功能,实现以上需求
一、测试自定义传参有效
[dcli@gd6g12s146-hadoop-namenode2 sql]$ hive -f test.sql --hivevar num='2'
SLF4J: Found binding in [jar:file:/home/vipshop/platform/hive-0.11.0-build/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
OK
_c0
2
Time taken: 6.141 seconds, Fetched: 1 row(s)
[dcli@gd6g12s146-hadoop-namenode2 sql]$ cat test.sql
select '${num}' from default.dual;
二、测试自定义设置有效
[dcli@gd6g12s146-hadoop-namenode2 sql]$ hive -f test.sql --hivevar num='2'
SLF4J: Found binding in [jar:file:/home/vipshop/platform/hive-0.11.0-build/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
OK
2
Time taken: 8.25 seconds, Fetched: 1 row(s)
[dcli@gd6g12s146-hadoop-namenode2 sql]$ cat test.sql
<span style="color:#ff6600;">set hive.cli.print.header=false;</span>
select '${num}' from default.dual;
三、测试注释 设置有效,支持'--'注释方法,但是不支持'#'(如果不是处女座,似乎也就够了。。。)
[dcli@gd6g12s146-hadoop-namenode2 sql]$ hive -f test.sql --hivevar num='2'
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
OK
_c0
2
Time taken: 4.639 seconds, Fetched: 1 row(s)
[dcli@gd6g12s146-hadoop-namenode2 sql]$ cat test.sql
--author: tony.li
--desc: test hive service(cli) conf
--
select '${num}' from default.dual;
如上,我们就可以实现对HQL脚本的工程化执行了(当然外面可以包装一个脚本,实现对常用参数的配置),然后配合调度系统进行调度执行。