本文主要是介绍shell脚本中写hive的sql语句,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
2.3 shell脚本中写hive语句
2.3.1 test.sh脚本内容
#!/bin/bash
analysis_date=$1
#开始执行方法
#/opt/hive-2.3.5/bin/hive -e "select count(1) from hv_orders_user_buckets"
echo "输入的参数变量为:$analysis_date"
hive -e "use hv_user_profile;select id from hv_user_index;"
说明:使用“hive -e xxx”语句,前提是配置好hive的环境变量才能这样写。
这个语句中一定要引入 表所在数据库(use xxx)。否则,提示not found table xxx。
hive的每个sql结束的都要有“;”分号。
2.3.2 执行结果
[www@1-11-100 opt]$ sh test.sh 2019
输入的参数变量为:2019
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive-2.3.5/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-2.7.5/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]
Logging initialized using configuration in jar:file:/opt/hive-2.3.5/lib/hive-common-2.3.5.jar!/hive-log4j2.properties Async: true
OK
Time taken: 5.257 seconds
OK
id
2
1
3
Time taken: 1.692 seconds, Fetched: 3 row(s)
[www@1-11-100 opt]$
2.4 在linux下执行hive语句
[www@1-11-100 opt]$ hive -e "use hv_user_profile;select * from hv_user_index;";
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/hive-2.3.5/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/hadoop-2.7.5/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]
Logging initialized using configuration in jar:file:/opt/hive-2.3.5/lib/hive-common-2.3.5.jar!/hive-log4j2.properties Async: true
OK
Time taken: 5.363 seconds
OK
id last_uid tb_name
2 333 hv
1 3836358 hv_users
3 444 hs
Time taken: 1.736 seconds, Fetched: 3 row(s)
[www@1-11-100 opt]$
这篇关于shell脚本中写hive的sql语句的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!