HIVE-执行hive的几种方式,和把HIVE保存到本地的几种方式


网上相关教程很多,这里我主要是简单总结下几种常用的方法,方便日后查询。

 

第一种,在bash中直接通过hive -e命令,并用 > 输出流把执行结果输出到制定文件

hive -e "select * from student where sex = ''" > /tmp/output.txt

 

第二种,在bash中直接通过hive -f命令,执行文件中一条或者多条sql语句。并用 > 输出流把执行结果输出到制定文件

 

hive -f exer.sql  > /tmp/output.txt

文件内容
select * from student where sex = '';
select count(*) from student;

 

第三种,在hive中输入hive-sql语句,通过使用INSERT OVERWRITE LOCAL DIRECTORY结果到本地系统和HDFS文件系统

语法一致,只是路径不同

insert overwrite local directory "/tmp/out"
 > select cno,avg(grade) from sc group by(cno);

 

insert overwrite directory 'hdfs://server71:9000/user/hive/warehouse/mystudent'
select * from student1;

 

以上是三种,包含了3执行hive-sql的方法。结果保存到本地的方法前两种都属于linxu BASH自带的方法。第三种才是HIVE本身的导出数据的方法。

 

第四种,就是基本的SQL语法,从一个表格中抽取数据,直接插入另外一个表格。参考SQL语法即可。

insert overwrite table student3 
select sno,sname,sex,sage,sdept from student3 where year='1996';

 http://blog.csdn.net/zhuce1986/article/details/39586189


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM