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';
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章