目录
三、insert into和insert overwrite区别
一、无分区表情况
1、创建表
create table stu(name string,age int)
row format delimited fields terminated by ',';
2、insert into插入数据
insert into table stu(name,age) values ("Lucy",22);
insert into table stu(name,age) values ("Lucy",22);
insert into table stu(name,age) values ("Lina",23);
Total MapReduce CPU Time Spent: 5 seconds 120 msec
hive> select * from stu;
OK
Lucy 22
Lucy 22
Lina 23
Time taken: 1.134 seconds, Fetched: 3 row(s)
3、继续insert overwrite插入数据
insert overwrite table stu values("Lucy",22);
hive> select * from stu;
OK
Lucy 22
Time taken: 0.074 seconds, Fetched: 1 row(s)
insert overwrite 经常 insert overwrite table stu select * from ....使用;
二、分区表情况
1、创建表
create table stu01(name string)
partitioned by(age int)
row format delimited fields terminated by ',';
2、insert into插入数据
insert into table stu01(name,age) values ("Lucy",22);
insert into table stu01(name,age) values ("Lucy",22);
insert into table stu01(name,age) values ("Lina",23);
hive> select * from stu01;
OK
Lucy 22
Lucy 22
Lina 23
Time taken: 0.088 seconds, Fetched: 3 row(s)
3、继续insert overwrite插入数据
insert overwrite table stu01 values ("Lucy",22);
hive> select * from stu01;
OK
Lucy 22
Lina 23
Time taken: 0.079 seconds, Fetched: 2 row(s)
hive> show partitions stu01;
OK
age=22
age=23
Time taken: 0.045 seconds, Fetched: 2 row(s)
三、insert into和insert overwrite区别
insert overwrite table 后面的表不能指明要插入的字段名,否则报错。insert into table可以。stu(name,age),紫色部分;
两者都可以向 hive 表中插入数据,但 insert into 操作是以追加的方式向 hive 表尾部追加数据,而 insert overwrite 操作则是直接重写数据,即先删除 hive 表的数据,再执行写入操作。注意,如果 hive 表是分区表的话,insert overwrite 操作只会重写当前分区的数据,不会重写其他分区数据。