天天看點

[Hive]Hive使用指南二 Hive指令的3種調用方式

版權聲明:本文為部落客原創文章,未經部落客允許不得轉載。 https://blog.csdn.net/SunnyYoona/article/details/51549329

1. 多語句執行 執行HQL腳本 http://gitlab.corp.qunar.com/jifeng.si/learningnotes/blob/master/IT/%E5%A4%A7%E6%95%B0%E6%8D%AE/Hive/%5BHive%5Dhive%E5%91%BD%E4%BB%A4%E7%9A%843%E7%A7%8D%E8%B0%83%E7%94%A8%E6%96%B9%E5%BC%8F.md#1-hql

hive –f  /root/shell/hive-script.sql
           

hive-script.sql類似于script一樣,直接寫查詢指令就行。

hive-script.sql是hive 語句的集合:

xiaosi@qunar:~$ vim hive_script.sql
select * from search_click;
select count(*) from search_click;
           

這裡可以和靜音模式-S聯合使用,通過第三方程式調用,第三方程式通過hive的标準輸出擷取結果集。

# 不會顯示mapreduct的操作過程
$HIVE_HOME/bin/hive -S -f /home/my/hive-script.sql 
           

2. 短語句執行 指令行執行HQL http://gitlab.corp.qunar.com/jifeng.si/learningnotes/blob/master/IT/%E5%A4%A7%E6%95%B0%E6%8D%AE/Hive/%5BHive%5Dhive%E5%91%BD%E4%BB%A4%E7%9A%843%E7%A7%8D%E8%B0%83%E7%94%A8%E6%96%B9%E5%BC%8F.md#2-hql

hive -e  'sql語句'
           

例如執行:

xiaosi@Qunar:~$ hive -e 'select * from t1'
           

靜音模式:(不會顯示mapreduce的操作過程)

xiaosi@Qunar:~$ hive -S -e 'select * from t1'
           

導出資料:

xiaosi@Qunar:~$ hive -e 'select * from t1'  > test.txt
           

3. 互動模式 http://gitlab.corp.qunar.com/jifeng.si/learningnotes/blob/master/IT/%E5%A4%A7%E6%95%B0%E6%8D%AE/Hive/%5BHive%5Dhive%E5%91%BD%E4%BB%A4%E7%9A%843%E7%A7%8D%E8%B0%83%E7%94%A8%E6%96%B9%E5%BC%8F.md#3

直接使用hive指令:

#hive     啟動
hive>quit;     退出hive
hive> show databases;   檢視資料庫
hive> create database test;  建立資料庫
hive> use default;    使用哪個資料庫
hive>create table t1 (key string); 建立表