Hive-表

Table 内部表

(1)与数据库中的Table在概念上类似
(2)每个Table在hive中都有一个相应的目录存储数据
(3)所有的Table数据都保存在这个目录中
(4)删除表时,元数据与数据都会被删除

    创建表
    create table t1(tid int, tname String, age int);
    create table t2(tid int, tname String, age int) location '/mytable/hive/t2'; // 指定在hdfs上的存储位置
    create table t3(tid int, tname String, age int) row format delimited fields terminated by ','; // 指定列与列之间的分隔符
    create table t4 as select * from t3;
    create table t5 row format delimited fields terminated by ' ' as select * from t3;
    查看表结构
    desc table_name;
    show create table table_name;
    添加表字段
    alter table table_name add columns (english int,chinese int);
    删除表
    drop table table_name;

Partition 分区表

     (1)Partition对应数据库的Partition列的密集索引
     (2)在Hive中,表中的一个Partition对应表下的一个目录,所有的Partition的数据都存储在对应的目录中

     创建表
     create table partition_table(id int, name String)partitioned by (gender String) row format delimited fields terminated by ',';
     插入
     insert into table partition_table partition(gender = 'M') select tid,tname from user where gender = 'M';

External Table 外部表

    (1)指向已经在hdfs中存在的数据,可以创建Partition
    (2)它和内部表在元数据的组织上是相同的,而实际数据的存储则有较大的差异
    (3)外部表只有一个过程,加载数据和创建表同时完成,并不会移动到数据仓库目录中,只是与外部数据建立一个链接。当删除一个外部表时,仅删除该链接。

    创建表
    create external table external_table (id int, name String, age int) row format delimited fields terminated by ',' location '/input';

Bucket Table 桶表

    (1)桶表是对数据进行哈希取值,然后放到不同文件夹中存储。
    create table bucket_table(id int, name String) clustered by(name) into 5 buckets row format delimited fields terminated by ',';

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值