【问题标题】:Not able to partition table on Hive- Error in metadata无法在 Hive 上分区表 - 元数据错误
【发布时间】:2016-03-09 21:49:24
【问题描述】:

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

我想在 Column spec: DoJ where value is 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

【问题讨论】:

  • 请提供您的创建表脚本和show partitions employee的输出
  • 我的解决方案有效吗?

标签: hadoop hive partition


【解决方案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,只需在 partitioned by 中将 year 替换为 DoJ。

【讨论】:

    猜你喜欢
    • 2016-12-13
    • 2022-01-18
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多