2013-03-20 224 views
0

我想通过以下命令在Hive中执行多次插入覆盖。HIVE中的多个插入覆盖区

INSERT OVERWRITE table results_3 SELECT NULL, res, NULL, NULL FROM results where field= 'title'; 

而且results_3表的第一个命令

NULL Up On Cripple Creek (2000 Digital Remaster) NULL NULL 
NULL The Weight (2000 Digital Remaster) NULL NULL 
NULL Rhythm Of The Rain (LP Version) NULL NULL 
NULL Who'll Stop the Rain NULL NULL 
NULL I Walk the Line NULL NULL 
NULL Against The Wind NULL NULL 
NULL Lyin' Eyes NULL NULL 
NULL North To Alaska NULL NULL 
NULL You Gave Me A Mountain NULL NULL 
NULL Night Moves NULL NULL 


INSERT OVERWRITE table results_3 SELECT NULL, NULL, res, NULL FROM results where field= 'albums'; 

而且results_3表的第二个命令

NULL NULL The Band NULL 
NULL NULL The Band NULL 
NULL NULL The Cascades NULL 
NULL NULL Creedence Clearwater Revival NULL 
NULL NULL Johnny Cash NULL 
NULL NULL Bob Seger NULL 
NULL NULL The Eagles NULL 
NULL NULL Johnny Horton NULL 
NULL NULL Marty Robbins NULL 
NULL NULL Bob Seger NULL 

后的内容后的内容,但我想两件事情一起合并。你有什么想法我可以解决这个问题吗?

感谢

+0

你如何匹配应合并行?你的表的模式是什么?如果结果表中有一个id,那么你可以执行JOIN。 – libjack 2013-03-25 14:42:28

回答

0

蜂房insert不支持迄今为止追加。

一个简单的方法:insert overwrite两个目录。手动合并它。 或 insert into一个表与不同的分区(但是,实际上不同的分区有不同的目录)。

Plz参见hive wiki了解更多信息。

+0

如何手动合并? – user1309258 2013-03-21 01:32:17

+1

'hadoop dfs -mv '或'hadoop dfs -getmerge' – pensz 2013-03-21 06:17:12

2

您可以附加在这样的方式:

INSERT OVERWRITE TABLE 
select col1 ... col2 
from 
(
SELECT col1 ... coln from TABLE --old data 
UNION ALL 
SELECT col1 ... col2n from TABLE2 --new data 
)