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]$

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值