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 ',';