INSERT OVERWRITE TABLE tablename2 [PARTITION (partcol1=val)]
Select * from tablename1 where partition_name=’va1’ or partition_name=val2;
eg:A表数据如下
id(String) name(String)
----------------------------
1 aaa
2 bbb
3 ccc
-----------------------------
要求更新2 bbb为2 ddd
hive脚本如下(TMP_A为分区表):
insert overwrite table TMP_A partition (p='one') select id,"ddd" from A where id = 2;
insert overwrite table TMP_A partition (p='two') select a.id,a.name from A a left outer join (select id from TMP_A where name='one') b on (a.id=b.id) where b.id is NULL:
insert overwrite table A select * from TMP_A where p='one' or p='two';
其实还有一种方法就是把要update的列建在A表,不用update的列建在B表,然后合并到C表,再重写原来的表。再把A,B,C表DROP掉
Delete语法:
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement
[WHERE where_condition]
[join table]
eg:A表数据如下
id(String) name(String)
----------------------------
1 aaa
2 bbb
3 ccc
-----------------------------
要求删除2 bbb
hive脚本如下:
insert overwrite table A select id,name from A where id !=2;
Select * from tablename1 where partition_name=’va1’ or partition_name=val2;
eg:A表数据如下
id(String) name(String)
----------------------------
1 aaa
2 bbb
3 ccc
-----------------------------
要求更新2 bbb为2 ddd
hive脚本如下(TMP_A为分区表):
insert overwrite table TMP_A partition (p='one') select id,"ddd" from A where id = 2;
insert overwrite table TMP_A partition (p='two') select a.id,a.name from A a left outer join (select id from TMP_A where name='one') b on (a.id=b.id) where b.id is NULL:
insert overwrite table A select * from TMP_A where p='one' or p='two';
其实还有一种方法就是把要update的列建在A表,不用update的列建在B表,然后合并到C表,再重写原来的表。再把A,B,C表DROP掉
Delete语法:
INSERT OVERWRITE TABLE tablename1 [PARTITION (partcol1=val1, partcol2=val2 ...)] select_statement1 FROM from_statement
[WHERE where_condition]
[join table]
eg:A表数据如下
id(String) name(String)
----------------------------
1 aaa
2 bbb
3 ccc
-----------------------------
要求删除2 bbb
hive脚本如下:
insert overwrite table A select id,name from A where id !=2;