本文介绍了SemanticException添加分区Hive表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试使用以下内容在Hive表上创建分区:
Attempting to create a partition on a Hive table with the following:
> alter table stock_ticker add if not exists
> partition(stock_symbol='ASP')
> location 'data/stock_ticker_sample/stock_symbol=ASP/'
哪个会产生以下输出
FAILED : SemanticException table is not partitioned but partition spec exists: {stock_symbol=ASP}
在尝试添加之前,该表上没有分区
There are no partitions on this table prior to this addition attempt
> show partitions stock_ticker;
这将导致
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.
Table stock_ticker_sample is not a partitioned table
毫无疑问,stock_symbol列存在且为字符串类型.
There is no question that the stock_symbol column exists and is of type string.
查询是要添加此分区需要采取哪些步骤?
The query is what steps need to be taken in order to add this partition?
推荐答案
解决方案是将分区信息添加到stock_ticker表的定义中:
Solution would be to add partitioning info into the definition of stock_ticker table:
CREATE EXTERNAL TABLE stock_ticker (
...
)
PARTITIONED BY (stock_symbol STRING);
然后,您可以轻松地通过以下方式将外部数据添加到表中:
Then easily you can add external data to your table by:
> alter table stock_ticker add if not exists
> partition(stock_symbol='ASP')
> location 'data/stock_ticker_sample/stock_symbol=ASP/'
GL!
这篇关于SemanticException添加分区Hive表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!