Hive,分区表的Bucketing

时间:2015-10-15 05:06:41

标签: hadoop hive bucket

这是我的剧本:

--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个桶”脚本工作正常。如何清空分区表

3 个答案:

答案 0 :(得分:0)

您可以使用以下语法创建带分区的bucketing表。

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; 

答案 1 :(得分:0)

在蜂巢中进行分组时,我们应该考虑一件重要的事情。

相同的列名不能同时用于分段和分区。原因如下:

群集和排序在分区内发生。在每个分区内部,只有一个与分区列关联的值(在您的情况下是年份),因此不会对群集和排序产生任何影响。这就是你错误的原因......

答案 2 :(得分:0)

当您进行动态分区时,创建一个包含所有列(包括分区列)的临时表,并将数据加载到临时表中。

使用分区列创建实际的分区表。在从临时表加载数据时,分区列应位于select子句的最后一列中。