Hive表实现一次查询多次插入需要注意的点

Hivesql里,为了提高查询效率,我们可以将通用的功能模块微服务化,除了可以使用with..as这种优化方式外,本文记录另外一种方式:from() insert into

如果目标表是普通表,则需要插入不同的表(tableB和tableC),插入同一个表会报错

from (select xx from tableA where xxx) sourcetable --需要起一个别名sourcetable

insert into tableB

select xx where xx --从sourcetable取数

insert into tableC

select xx where xx --从sourcetable取数

...

如果目标表是分区表,目前博主自测只支持单分区表数据插入,静态分区和动态分区插入均可,如果是双分区,则会报错

from (select xx from tableA where xxx) sourcetable --需要起一个别名sourcetable

insert into Partition_tableB partition(p_col = 'A') --静态指定分区

select xx where xx 

insert into Partition_tableB partition(p_col) --动态不指定分区

select xx,'B' where xx 

...

 

你可能感兴趣的:(大数据)