Insert data in many partitions using one insert statement

我是研究僧i 提交于 2019-12-24 07:35:22

问题


I have table A and table B, where B is the partitioned table of A using a field called X.

When I want to insert data from A to B, I usually execute the following statement:

INSERT INTO TABLE B PARTITION(X=x) SELECT <columnsFromA> FROM A WHERE X=x

Now what I want to achieve is being able to insert a range of X, let's say x1, x2, x3... How can I achieve this in one single statement?


回答1:


Use dynamic partition load:

set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;

INSERT OVERWRITE TABLE table_B PARTITION(X)
select 
col_1,
col_2,
...
col_N,
X --partition column is the last one
 from 
      table_A
where X in ('x1', 'x2', 'x3'); --filter here

Or use select * from table_A if the order of columns in A and B is the same. Partition column (X) should be the last one.



来源:https://stackoverflow.com/questions/48901332/insert-data-in-many-partitions-using-one-insert-statement

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!