HIVE CLI参数介绍:
使用help命令可以查看hive cli参数
-d:指定变量
-e:运行SQL语句
-f:执行sql脚本
-i:初始化sql文件
-S:静默模式,不会打印MapReduce输出信息
-v:打印执行sql
-d,--define <key=value> Variable substitution 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
--hiveconf <property=value> Use value for given property
--hivevar <key=value> Variable substitution to apply to Hive
commands. e.g. --hivevar A=B
-i <filename> Initialization SQL file
-S,--silent Silent mode in interactive shell
-v,--verbose Verbose mode (echo executed SQL to the console)
hive -f:
hive -f test.sql
hive -e:
hive -e "select * from test.test8"
hive -S -v -e :
-S:静默模式,不打印MapReduce输出信息
-v:打印执行sql
–hiveconf :设置参数,也可以用来传参
案例:
[hadoop@172 chengpeng]$ hive -v -S --hiveconf hive.cli.print.header=true -e "select user_id,name,address from test.test8 group by user_id,name,address"
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/service/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/service/hive/spark/jars/slf4j-log4j12-1.7.16.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/service/tez/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/service/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
select user_id,name,address from test.test8 group by user_id,name,address
user_id name address
1 xiaoming shanghai
2 xiaolan beijing
–hiveconf :用来传参
sql脚本:
select * from test.test6 where day='${hiveconf:day}' and requesturl like '%${hiveconf:url}%' limit 15;
hive -hiveconf day=20151115 -hiveconf url=licaike -f test.sql