建表:内部表、外部表、分区表、桶表
内部表:
create table if not exists student(
id int,name string,age int,sex string
)row format delimited
fields terminated by "\t";
查看创建表的信息
show create table student;
查看表结构(列)信息
desc student;
导入数据方法一:
load data local inpath '/home/tg/datas/students' overwrite into table student;
外部表:
create external table if not exists stutest(
id int,name string,age int,sex string
)row format delimited
fields terminated by "\t"
location '/input/stutest';
导入数据方法二:
hadoop fs -put students /input/stutest/
create table student
as
select * from stus;
分区表:
单分区:
create table if not exists stutest(
id int,name string,age int,sex string
)partitioned by (grade string)
row format delimited
fields terminated by "\t";
load data local inpath '/home/tg/datas/students' overwrite into table stutest partition (grade='g1');
双分区:
create table if not exists stutest2(
id int,name string,age int,sex string
)partitioned by (grade string,class string)
row format delimited
fields terminated by "\t";
load data local inpath '/home/tg/datas/students' overwrite into table stutest2 partition (grade='g1',class='c1');
alter table stutest2 drop partition (grade='g1',class='c1');
Join查询;
inner join
outer join:left right full
内部表:
create table if not exists student(
id int,name string,age int,sex string
)row format delimited
fields terminated by "\t";
查看创建表的信息
show create table student;
查看表结构(列)信息
desc student;
导入数据方法一:
load data local inpath '/home/tg/datas/students' overwrite into table student;
外部表:
create external table if not exists stutest(
id int,name string,age int,sex string
)row format delimited
fields terminated by "\t"
location '/input/stutest';
导入数据方法二:
hadoop fs -put students /input/stutest/
create table student
as
select * from stus;
分区表:
单分区:
create table if not exists stutest(
id int,name string,age int,sex string
)partitioned by (grade string)
row format delimited
fields terminated by "\t";
load data local inpath '/home/tg/datas/students' overwrite into table stutest partition (grade='g1');
双分区:
create table if not exists stutest2(
id int,name string,age int,sex string
)partitioned by (grade string,class string)
row format delimited
fields terminated by "\t";
load data local inpath '/home/tg/datas/students' overwrite into table stutest2 partition (grade='g1',class='c1');
alter table stutest2 drop partition (grade='g1',class='c1');
Join查询;
inner join
outer join:left right full