铲斗不是在hadoop-hive上创造的

时间:2015-04-05 14:42:06

标签: hive buckets

我正在尝试使用以下命令在配置单元中创建一个存储桶:

hive> create table emp( id int, name string, country string)
 clustered by( country)
row format delimited
fields terminated by ','
stored as textfile ;

命令正在成功执行:当我将数据加载到此表中时,它会成功执行,并且在使用select * from emp时会显示所有数据。

但是,在HDFS上,它只创建一个表,只有一个文件包含所有数据。也就是说,没有特定国家/地区记录的文件夹。

1 个答案:

答案 0 :(得分:1)

首先,在DDL语句中,您必须明确提到您想要多少个桶。

create table emp( id int, name string, country string)
 clustered by( country)
INTO 2 BUCKETS
row format delimited
fields terminated by ','
stored as textfile ;

在上面的陈述中我提到了2个桶,同样你可以提到你想要的任何数字。

你仍然没有完成!!

之后,在将数据加载到表格中时,您还必须提到下面的hive提示。

set hive.enforce.bucketing = true;  

应该这样做。

在此之后,您应该能够看到在表目录下创建的文件数与DDL语句中提到的桶数相同。

Bucketing不会创建HDFS文件夹,而是如果您想为一个国家/地区创建单独的floder,那么您应该进行PARTITION。

请详细了解hive分区和分组。