第一种,在bash中直接通过hive -e命令,并用 > 输出流把执行结果输出到制定文件
hive -e "select * from test.hour_rate2 where year='2019'" > /tmp/output_1.txt
第二种,在bash中直接通过hive -f命令,执行文件中一条或者多条sql语句。并用 > 输出流把执行结果输出到制定文件
hive -f /tmp/exer.sql > /tmp/output_3.txt
exer.sql 文件内容
use test;
select * from hour_rate2 where year = '2018';
select count(*) from hour_rate2;
第三种,进入hive环境中输入hive-sql语句
以上是三种,包含了3执行hive-sql的方法。
前两种都属于linxu BASH自带的方法。第三种才是HIVE本身的方法.