2014-06-16 93 views
4

我想创建一个使用动态分区的分区表,但我面临一个问题。我在Hortonworks Sandbox 2.0上运行Hive 0.12。蜂巢动态分区

set hive.exec.dynamic.partition=true; 
INSERT OVERWRITE TABLE demo_tab PARTITION (land) 
SELECT stadt, geograph_breite, id, t.country 
FROM demo_stg t; 

但是它不工作..我得到一个错误。

下面是创建该表demo_stg查询:

create table demo_stg 
(
    country STRING, 
    stadt STRING, 
    geograph_breite FLOAT, 
    id INT 
    ) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY "\073"; 

而且DEMO_TAB

CREATE TABLE demo_tab 
(
    stadt STRING, 
    geograph_breite FLOAT, 
    id INT 
) 
PARTITIONED BY (land STRING) 
ROW FORMAT DELIMITED FIELDS TERMINATED BY "\073"; 
  • demo_stg也充满了数据,所以它的不是空的。

感谢您的帮助:)

+0

什么是你所得到的错误? – visakh

+0

也尝试添加SET hive.exec.dynamic.partition.mode = nonstrict; –

+0

如果我尝试运行“SET hive.exec.dynamic.partition.mode = nonstrict;”我收到一个错误。我得到的每个错误消息都是这样的:“执行配置单元查询时发生错误:未知异常。” – Baeumla

回答

9

您需要修改您的选择:

set hive.exec.dynamic.partition=true; 
INSERT OVERWRITE TABLE demo_tab PARTITION (land) 
SELECT stadt, geograph_breite, id, t.country 
FROM demo_stg t; 

我不知道在您的演示其列分期要执行分区或演示其列对应于土地。但无论是列应该是存在于选择最后一栏说您的演示表的列名是id,这样你的选择应该写成:

INSERT OVERWRITE TABLE demo_tab PARTITION (land) 
SELECT stadt, geograph_breite, id, t.country,t.id as land 
FROM demo_stg t; 

我认为这应该工作。

+0

感谢您的帮助:) Select: “INSERT OVERWRITE TABLE demo_tab PARTITION(land)SELECT stadt,geograph_breite,id,t.country,t.id as land FROM demo_stg t;”作品! – Baeumla

+0

我很高兴它的工作。和你的欢迎。此外,如果您有多个要分区的列,则选择应该包含多个,如您在插入语句后在PARTITION子句中指定的顺序。几天前,我已经写了一篇关于同样的博客http://exploredatascience.blogspot.in/2014/06/dynamic-partitioning-with-hive.html – Tanveer

2

分区列需要是选择查询中的最后一列。

还有一件事比设置您需要设置模式,不严格的分区为true其他:

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