hive中一共有以下几种建表方式:
create table person
(
id int,
name string,
hobbies array<string>,
address map<string,string>
)
row format delimited
fields terminated by ',';
collection items terminated by '-';
map keys terminated by ':';
创建外部表:
create external table person
(
id int,
name string,
hobbies array<string>,
address map<string,string>
)
row format delimited
fields terminated by ',';
collection items terminated by '-';
map keys terminated by ':';
location '/root/date/person'
根据已有的表创建表:
create table person1 as select id, name, hobbies, address from person0
like创建表:
create table person1 like person0
加载数据:
load data local inpath '/tmp/data/person0_data' into table person
load data local inpath'/tmp/date/person0' into table person
创建分区表:
create table person1
(
id int,
name string,
hobbies array<string>,
address map<string,string>
)
partition by (age int)/(sex string)
row format delimited
fields terminated by ',';
collection items terminated by '-';
map keys terminated by ':';
给分区表加载数据:
load data local iinpath '/root/data/person' into table person1 partition (age=1)
添加、删除分区:
alter table person4 add partition(sex = '3',age = '1')
alter table person1 add partition(sex = '1')
alter table person2 drop partition(sex = '2')
alter table person3 drop partition(sex = '3')
DML:data manipulation language
在hive中多次load相同的文件,数据会被追加,而不是覆盖。
使用beeline的连接方式:
beeline -u jdbc:hive2//node04:10000 -n root
beeline