2015-10-15 91 views
0

這是我的腳本:蜂巢,桶裝的分區表

--table without partition 

drop table if exists ufodata; 
create table ufodata (sighted string, reported string, city string, shape string, duration string, description string) 
row format delimited 
fields terminated by '\t' 
Location '/mapreduce/hive/ufo'; 

--load my data in ufodata 

load data local inpath '/home/training/downloads/ufo_awesome.tsv' into table ufodata; 

--create partition table 
drop table if exists partufo; 
create table partufo (sighted string, reported string, city string, shape string, duration string, description string) 
partitioned by (year string) 
clustered by (year) into 6 buckets 
row format delimited 
fields terminated by '/t'; 

--by default dynamic partition is not set 
set hive.exec.dynamic.partition=true; 
set hive.exec.dynamic.partition.mode=nonstrict; 
--by default bucketing is false 
set hive.enforcebucketing=true; 

--loading mydata 
insert overwrite table partufo 
partition (year) 
select sighted, reported, city, shape, min, description, SUBSTR(TRIM(sighted), 1,4) from ufodata; 

錯誤消息:

失敗:錯誤的語義分析:無效的列引用

我試過了瓢潑大雨爲我的分區表。如果我刪除「由(年)聚集成6桶」的腳本工作正常。如何分區分區表

回答

0

您可以使用以下語法創建分區表分區表。

CREATE TABLE bckt_movies 
(mov_id BIGINT , mov_name STRING ,prod_studio STRING, col_world DOUBLE , col_us_canada DOUBLE , col_uk DOUBLE , col_aus DOUBLE) 
PARTITIONED BY (rel_year STRING) 
CLUSTERED BY(mov_id) INTO 6 BUCKETS; 
+0

Puneeth的語法也差不多...... – madhu

+0

那麼這個腳本有什麼問題呢?我可以在分區表上創建分區嗎?腳本:gist.github.com/puneethbs/207dc89530c26c05ed02錯誤消息:gist.github.com/puneethbs/3dcdebb4075275bbf62b – Puneeth

0

有一件重要的事情,我們應該考慮在蜂巢中進行分段處理。

相同的列名不能同時用於分段和分區。原因如下:

集羣和排序發生在一個分區內。在每個分區內只有一個與分區列相關的值(在你的情況下是年份),因此不會對聚類和排序產生任何影響。這就是你的錯誤的原因....

+0

不,這沒有奏效。我仍然得到同樣的錯誤。 SUBSTR(TRIM(sighted),1,4)是從列中提取的年份 – Puneeth

+0

腳本:https://gist.github.com/puneethbs/207dc89530c26c05ed02錯誤消息:https://gist.github.com/puneethbs/ 3dcdebb4075275bbf62b – Puneeth

+0

只給一個別名給SUBSTR(TRIM(sighted),1,4)作爲一年....已經在我的回答中編輯過了...希望這有助於 – madhu

0

當你做動態分區時,創建一個包含所有列(包括你的分區列)的臨時表並將數據加載到臨時表中。

用分區列創建實際的分區表。在從臨時表中加載數據時,分區列應該位於select子句的最後一列。