【轉】Hive內部表、外部表格

來源:互聯網
上載者:User

標籤:

hive內部表、外部表格區別自不用說,可實際用的時候還是要小心。

1. 內部表:

 

[sql] view plaincopyprint? 
  1. create table tt (name string , age string) location ‘/input/table_data‘;  


此時,會在hdfs上建立一個tt表的資料存放地,例如,筆者是在 hdfs://master/input/table_data 

 

上傳hdfs資料到表中:

 

[sql] view plaincopyprint? 
  1. load data inpath ‘/input/data‘ into table tt;  


此時會將hdfs上的/input/data目錄下的資料轉移到/input/table_data目錄下。

 

刪除tt表後,會將tt表的資料和中繼資料資訊全部刪除,即最後/input/table_data下無資料,當然/input/data下再上一步已經沒有了資料!

如果建立內部表時沒有指定location,就會在/user/hive/warehouse/下建立一個表目錄,其餘情況同上。

注意的地方就是:load data會轉移資料!

2. 外部表格:

 

[sql] view plaincopyprint? 
  1. create external table et (name string , age string);  


此時,會在/user/hive/warehouse/建立一個表目錄et

 

 

[sql] view plaincopyprint? 
  1. load data inpath ‘/input/edata‘ into table et;  

 

此時會把hdfs上/input/edata/下的資料轉到/user/hive/warehouse/et下,刪除這個外部表格後,/user/hive/warehouse/et下的資料不會刪除,但是/input/edata/下的資料在上一步load後已經沒有了!資料的位置發生了變化!本質是load一個hdfs上的資料時會轉移資料!

3. 其他:

 

(1)加上location用法一樣,只不過表目錄的位置不同而已。

(2)加上partition用法也一樣,只不過表目錄下會有分區目錄而已。

(3)load data local inpath直接把本地檔案系統的資料上傳到hdfs上,有location上傳到location指定的位置上,沒有的話上傳到hive預設配置的資料倉儲中。

【轉】Hive內部表、外部表格

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.