这是我的脚本:
--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;
错误信息:
FAILED:语义分析出错:列引用无效
我尝试了分区表 . 如果我删除“由(年)聚集到6个桶”脚本工作正常 . 如何清空分区表
3 回答
您可以使用以下语法创建带分区的bucketing表 .
在蜂巢中进行分组时,我们应该考虑一件重要的事情 .
The same column name cannot be used for both bucketing and partitioning. 原因如下:
群集和排序在分区内发生 . 在每个分区内部,只有一个与分区列关联的值(在您的情况下是年份),因此不会对群集和排序产生任何影响 . 这就是你错误的原因....
在进行动态分区时,创建一个包含所有列(包括分区列)的临时表,并将数据加载到临时表中 .
使用分区列创建实际分区表 . 在从临时表加载数据时,分区列应位于select子句的最后一列中 .