无法在Hive中对表进行分区 - 元数据中出错

时间:2015-12-04 20:50:41

标签: hadoop hive partition

我在Hive中创建了一个表,其中加载了数据。

我想在Column规范上划分它:DoJ,其值为2012

我用过:

ALTER TABLE employee
ADD PARTITION (year='2012')
location '/home/rvarun/2012/part2012';

我收到错误:

FAILED: Error in metadata: table is not partitioned but partition spec exists: {year=2012}
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask

我对Hive有点新鲜,所以请原谅我的任何小说。

我看到的表格如下:

1001    Varun   100000  Security Lead   2011
1002    Saloni  85000   Database Admin  2012
1003    Karan   90000   Network Engineer Lead   2012
1004    Pratik  98000   TrainEngine Driver  2012
1005    Ashish  120000  Senior Consultant   2013
1006    Gautam  70000   Salesforce Consultant   2013
1007    Mohit Sacheva   20000   Peon    2014

谁能告诉我为什么会这样? TIA

1 个答案:

答案 0 :(得分:1)

您的表格未正确创建。假设您的表名是my_table。你应该包括

'PARTITIONED BY (year string)'

所以你的创建表应该如下所示

DROP TABLE IF EXISTS my_table;
CREATE EXTERNAL TABLE my_table 
(col1 string,
col2 string,
col3 string)
PARTITIONED BY (year string)
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
STORED AS TEXTFILE
LOCATION '/home/rvarun/2012/part2012';

如果要将列名称用作DoJ,只需将year替换为分区为的DoJ。