hive创建表、数据库、分区和分桶及其他语句

create table ts01(id int,name string);

hive (default)> create table ts02(id int,name string)row format delimited fields terminated by ','、

hive (default)> create table ts03(id int,name string)partitioned by(dt string) row format delimited fields terminated by ',';

hive (default)> create table ts04(id int,name string)partitioned by(dt string,Tm string) row format delimited fields terminated by ',';

注意,这里dt和tm是子父级的关系,
alter table ts04 add partition(dt='2018-06-03',tm='15-41');
 alter table ts04 add partition(dt='2018-06-03',tm='15-45');

赋值一个表的结构,注意只是重新创建了一个和之前表结构一样的表,但是不加载前一张表的数据,即新复制出来的表是一张空表
create table ts03 like ts02;

对一张表添加分桶
create table ts05(id int,name string)clustered by(id) into 3 buckets row format delimited fields terminated by ',';
对一张表里的一个分区添加分桶
create table ts05(id int,name string)partitioned by(dt string) clustered by(id) into 3 buckets row format delimited fields terminated by ',';

清空表中的数据
truncate table ts01;

猜你喜欢

转载自my.oschina.net/u/3197158/blog/1823501
今日推荐