Hive 动态分区不能是静态分区的父级

Hive 动态分区不能是静态分区的父级,hive,Hive,我正在尝试从Hive中的另一个表中的1个表(其数据每月重新计算)聚合数据(保存相同的数据,但始终保持不变)。但是,每当我尝试组合数据时,都会出现以下错误: FAILED: SemanticException [Error 10094]: Line 3:74 Dynamic partition cannot be the parent of a static partition 'category' 我用于创建表的代码如下所示: create table my_data_by_category

我正在尝试从Hive中的另一个表中的1个表(其数据每月重新计算)聚合数据(保存相同的数据,但始终保持不变)。但是,每当我尝试组合数据时,都会出现以下错误:

FAILED: SemanticException [Error 10094]: Line 3:74 Dynamic partition cannot be the parent of a static partition 'category'
我用于创建表的代码如下所示:

create table my_data_by_category (views int, submissions int)
    partitioned by (category string)
    row format delimited
    fields terminated by ','
    escaped by '\\'
    location '${hiveconf:OUTPUT}/${hiveconf:DATE_DIR}/my_data_by_category';

create table if not exists my_data_lifetime_total_by_category
    like my_data_by_category
    row format delimited
    fields terminated by ','
    escaped by '\\'
    stored as textfile
    location '${hiveconf:OUTPUT}/lifetime-totals/my_data_by_category';
我用来填充表格的代码如下:

insert overwrite table my_data_by_category partition(category)
    select mdcc.col1, mdcc2.col2, pcc.category
    from my_data_col1_counts_by_category mdcc
    left outer join my_data_col2_counts_by_category mdcc2 where mdcc.category = mdcc2.category
    group by mdcc.category, mdcc.col1, mdcc2.col2;

insert overwrite table my_data_lifetime_total_by_category partition(category)
   select mdltc.col1 + mdc.col1 as col1, mdltc.col2 + mdc.col2, mdc.category
   from my_data_lifetime_total_by_category mdltc
   full outer join my_data_by_category mdc on mdltc.category = mdc.category
   where mdltc.col1 is not null and mdltc.col2 is not null;

令人沮丧的是,我将此数据分区到另一列上,并且使用该分区重复相同的过程不会出现问题。我曾尝试在谷歌上搜索“动态分区不能是静态分区的父分区”错误消息,但我找不到任何关于这是什么原因或如何修复的指导。我很确定我的一个或多个表的设置方式存在问题,但我看不出有什么问题。导致此错误的原因以及我能做些什么来解决它?

此脚本中没有PARTITED by子句。当您试图使用insert语句中的partition插入到非分区表中时,它失败了

create table if not exists my_data_lifetime_total_by_category
    like my_data_by_category
    row format delimited
    fields terminated by ','
    escaped by '\\'
    stored as textfile
    location '${hiveconf:OUTPUT}/lifetime-totals/my_data_by_category';

不需要。您不需要添加分区子句

您正在执行
按mdcc.category分组
中的
插入覆盖表my_data_by_category partition(category)…
。但是您没有使用任何UDAF。
您确定可以这样做吗?

我认为如果您将第二条create语句更改为:

create table if not exists my_data_lifetime_total_by_category
partitioned by (category string)
row format delimited
fields terminated by ','
escaped by '\\'
stored as textfile
location '${hiveconf:OUTPUT}/lifetime-totals/my_data_by_category';

然后您应该没有错误

但是如果my_data_by_category被分区,那么like子句不应该将该分区带到my_data_lifetime_total_by_category吗?不,您需要将partition子句定义为DDL命令的一部分。在测试配置单元脚本时,每次尝试添加“partitioned by”子句都会产生错误。同样,我还有其他多个表,这些表在不显式添加分区的情况下工作,因此我不明白为什么这1个表会出现问题。能否共享用于创建表和插入命令的DDL命令?创建表和插入覆盖表命令在原始问题中,您可以按类别搜索my_data_lifetime_total_以查看它们。category是mdcc中的一个字段,因此不需要UDAF。在select子句中没有您尝试按其进行分组的mdcc.category列。我的意思是有输入错误。您正在使用“mdcc.category”而不是“pcc.category”。您可以在GROUPBY或SELECT子句中进行更改。我知道这确实很旧,但我遇到了此问题,并且没有关于此错误的任何信息。至少对我来说,问题是由于计算字段没有列别名。在上述情况下,
mdltc.col2+mdc.col2
应该是
mdltc.col2+mdc.col2作为col2
。关于错误的任何信息都不能表明这是问题所在,但这绝对是解决问题的原因。