使用一条插入语句在多个分区中插入数据
Insert data in many partitions using one insert statement
我有 table A 和 table B,其中 B 是使用名为 X 的字段对 A 进行分区 table。
当我要从A向B插入数据时,一般会执行如下语句:
INSERT INTO TABLE B PARTITION(X=x) SELECT <columnsFromA> FROM A WHERE X=x
现在我想要实现的是能够插入一系列 X,比方说 x1、x2、x3...我怎样才能在一个语句中实现这一点?
使用动态分区加载:
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
如果 A 和 B 中的列顺序相同,则使用 select * from table_A
。分区列 (X) 应该是最后一个。
我有 table A 和 table B,其中 B 是使用名为 X 的字段对 A 进行分区 table。
当我要从A向B插入数据时,一般会执行如下语句:
INSERT INTO TABLE B PARTITION(X=x) SELECT <columnsFromA> FROM A WHERE X=x
现在我想要实现的是能够插入一系列 X,比方说 x1、x2、x3...我怎样才能在一个语句中实现这一点?
使用动态分区加载:
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
如果 A 和 B 中的列顺序相同,则使用 select * from table_A
。分区列 (X) 应该是最后一个。