hive內部表、外部表、分區表、視圖


1、Table 內部表
    1).與數據庫中的Table在概念上是類似的
    2).每一個Table在Hive中都有一個相應的目錄存儲數據
    3).所有的Table數據(不包括 External Table) 都保存在這個目錄中
    4).刪除表時,元數據與數據都會被刪除
    5).建表:

 

2、Partition 分區表
    1).Partition 對應於數據庫的Partition列的密集索引
    2).在Hive中,表中的一個Partition對應於表下的一個目錄,所有的Partition的數據都存儲在對應的目錄中。
    3).建表:
hive> create table partition_table
    > (sid int, sname string) > partitioned by (gender string) > row format delimited fields terminated by ',';

3、External Table 外部表
    1).指向已經在HDFS中存在的數據,可以創建Partition
    2).它和內部表在元數據的組織上是相同的,而實際數據的存儲則有較大的差異
    3).外部表只有一個過程,加載數據和創建表同時完成,並不會移動到數據庫目錄中,知識與外部數據建立一個連接。當刪除一個外部表時,僅刪除連接。
    4).建表:
hive> create external table external_student > (sid int,sname string,age int) > row format delimited fields terminated by ',' > location '/input';
4、Bucket Table 桶表
    1). 桶表是對數據進行哈希取值,值不同的放到不同的文件中存儲。
    2). 建表:
hive> create table bucket_table 
    > (sid int,sname string,age int) > clustered by(sname) into 5 buckets;

5、視圖
1)視圖是一種虛表,是一個邏輯概念;可以跨越多張表
2)視圖建立在已有表的基礎上,視圖賴以建立的這些表稱為基表
3)視圖可以簡化復雜的查詢
4)建立視圖:
hive> create view empinfo
    > as 
    > select e.empno,e.ename,e.sal,e.sal*12 annlsal,d.dname > from emp e,dept d > where e.deptno=d.deptno;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM