Hive 用户接口主要有三个:
命令行(CLI)---最常用,启动的时候,会同时启动一个 Hive 服务。
客户端(Client) ---Client 是 Hive 的客户端,用户连接至 Hive Server。在启动 Client 模式的时候,需要指出 Hive Server 所在节点,并且在该节点启动 Hive Server。
Web界面(WUI)---WUI 是通过浏览器访问 Hive的Web工具
【Hive】命令------hive命令的3种调用方式
方式1:hive –f /root/shell/hive-script.sql(适合多语句)
hive-script.sql类似于script一样,直接写查询命令就行,不进入交互模式,执行一个hive script
这里可以和静音模式-S联合使用,通过第三方程序调用,第三方程序通过hive的标准输出获取结果集。
$HIVE_HOME/bin/hive -S -f /home/my/hive-script.sql (不会显示mapreduct的操作过程)
那么问题来了:如何传递参数呢?
demo如下:
start_hql.sh 内容:
#!/bin/bash
# -S 打印输出mapreduce日志
hive \
-hivevar id=1 \
-hivevar col2=2 \
-S -f test.sql
test.sql 内容:
use tmp;
select * from tmp_jzl_20140725_test11 where id='${hivevar:id}' and col2='${hivevar:col2}';
#!/bin/bash
source ~/.bash_profile
cd /home/ml/rwdPredict
yesterday=`date -d yesterday "+%Y-%m-%d"`
echo $yesterday"===start"
echo "batch sql start"
# hive -hiveconf v_begin_date=2019-07-25 -hiveconf v_end_date=2019-07-28 -f ml_risk_.sql
#echo "hive -hiveconf v_begin_date=$yesterday -hiveconf v_end_date=$yesterday -f ml_risk.sql"
hive -f ml_rwd.sql
echo "batch sql end"
echo "rwdPredict model start"
python3 rwdPredict.py
echo "rwdPredict model end"
echo $yesterday"===end"
方式2:hive -e 'sql语句'(适合短语句)
直接执行sql语句
例如:
[root@cloud4 shell]# hive -e 'select * from t1'
静音模式:
[root@cloud4 shell]# hive -S -e 'select * from t1' (用法与第一种方式的静音模式一样,不会显示mapreduce的操作过程)
此处还有一亮点,用于导出数据到linux本地目录下
例如:
[root@cloud4 shell]# hive -e 'select * from t1