hive的多插语句可以只扫描一次数据源表,往多张目标表插入数据,减少对数据源表的扫描次数。
from table1
insert overwrite/into table2 select [cols,…] where cond2
insert overwrite/into table3 select [cols,…] where cond3
insert overwrite/into table4 select [cols,…] where cond4
…
;
测试数据:
drop table if exists default.test001;
create table if not exists default.test001(
s_name string,
s_course map<string, int>
) comment 'name_course'
row format delimited
fields terminated by '\t'
collection items terminated by ','
map keys terminated by ':';
drop table if exists default.test002;
create table if not exists default.test002(
s_course string,
c_cnt int
) comment 'course_count';
drop table if exists default.test003;
create table if not exists default.test003(
s_name string,

本文介绍了Hive如何使用from insert语法进行多表插入操作,以减少数据源扫描次数。同时,针对Hive中map数据类型在insert语句中的使用问题进行了探讨,提供了两种解决方法,并提到了lateral view和explode等语法的应用,帮助优化代码效率。
最低0.47元/天 解锁文章
491

被折叠的 条评论
为什么被折叠?



