簡體   English   中英

Hive 將數據從一個分區復制到另一個

[英]Hive copy data from one partition to another

我有一個按日期分區的 hive 表。 我有日期為“2020-08-18”的數據。 我想將相同的數據復制(復制)到另一個分區。

有沒有這樣的命令來做到這一點

SELECT * FROM table_a WHERE date = "2020-08-18" INTO table_a WHERE date = "2020-08-10" 

以下查詢可能對您有所幫助,

INSERT OVERWRITE TABLE table_a PARTITION (odate="2020-08-18") 
select empdate,empvalue from table_a where odate='2020-08-10';

注意:不要在 select 語句中包含分區列。

create table if not exists table_a (empdate string, empvalue string) PARTITIONED BY 
(odate string) row format delimited fields terminated by ',' stored as textfile;

INSERT OVERWRITE TABLE table_a PARTITION (odate="2020-08-10") 
values ('101001','A'),('200101','B'),('100619','C'),('110707','D');

hive> select * from table_a;
OK
101001  A       2020-08-10
200101  B       2020-08-10
100619  C       2020-08-10
110707  D       2020-08-10

-- dont include the odate column in the select statement otherwise it will lead
-- to  Cannot insert into target table because column number/types are different
-- '"2020-08-18"': Table insclause-0 has 2 columns, but query has 3 columns error.


INSERT OVERWRITE TABLE table_a PARTITION (odate="2020-08-18") 
select empdate,empvalue from table_a where odate='2020-08-10';

hive> select * from table_a;
OK
101001  A       2020-08-10
200101  B       2020-08-10
100619  C       2020-08-10
110707  D       2020-08-10
101001  A       2020-08-18
200101  B       2020-08-18
100619  C       2020-08-18
110707  D       2020-08-18

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM