美文网首页
hive内部表、外部表、分区表、视图

hive内部表、外部表、分区表、视图

作者: chuweiyan | 来源:发表于2020-11-07 00:26 被阅读0次

    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;

    相关文章

      网友评论

          本文标题:hive内部表、外部表、分区表、视图

          本文链接:https://www.haomeiwen.com/subject/qxlfsktx.html