尝试使用以下内容在Hive表上创建分区:
> 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}
在此添加尝试之前,此表上没有分区
> 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列存在且类型为字符串。
查询是要添加此分区需要采取的步骤吗?
答案 0 :(得分:6)
解决方案是将分区信息添加到stock_ticker表的定义中:
CREATE EXTERNAL TABLE stock_ticker (
...
)
PARTITIONED BY (stock_symbol STRING);
然后您可以通过以下方式轻松地将外部数据添加到表格中:
> alter table stock_ticker add if not exists
> partition(stock_symbol='ASP')
> location 'data/stock_ticker_sample/stock_symbol=ASP/'
GL!