加入Spark Dataframe时出现意外的失败断言错误-发现重复的重写属性

问题描述

当我运行下面的代码时,出现错误 java.lang.AssertionError:断言失败:找到重复的重写属性。在更新我们的databricks运行时之前,该过程运行平稳。

  1. top10_df是列表groups中具有唯一键的数据的数据框。

  2. res_df是top10_df中具有最小和最大日期的唯一键的集合。

  3. 一旦创建并保留res_df,它就重新加入组中唯一键的top10_df中。

groups = ['col1','col2','col3','col4']
min_date_created = fn.min('date_created').alias('min_date_created')
max_date_created = fn.max('date_created').alias('max_date_created')

res_df = (top10_df
            .groupBy(groups)
            .agg(min_date_created,max_date_created
            )
         )
res_df.persist()
print(res_df.count())

score_rank = fn.row_number().over(w.partitionBy(groups).orderBy(fn.desc('score')))
unique_issue_id = fn.row_number().over(w.orderBy(groups))

out_df = (top10_df.alias('t10')
                    .join(res_df.alias('res'),groups,'left')
                    .where(fn.col('t10.date_created')==fn.col('res.max_date_created'))
                    .drop(fn.col('t10.date_created'))
                    .drop(fn.col('t10.date_updated'))
                    .withColumn('score_rank',score_rank)
                    .where(fn.col('score_rank')==1)
                    .drop('score_rank','latest_revision_complete_hash','latest_revision_durable_hash'
                         )
                    .withColumn('unique_issue_id',unique_issue_id)
                   .withColumnRenamed('res.id','resource_id')
                  )

out_df.persist()
print(out_df.count())

解决方法

代替: out_df = (top10_df.alias('t10') .join(res_df.alias('res'),groups,'left')

在加入之后,选择右侧 df 中的所有列并为其添加别名,以消除重复属性的歧义:

out_df = (top10_df.alias('t10')
.join(res_df.alias('res')
.select(fn.col('groups').alias('groups'),fn.col('min_date_created').alias('min_date_created'),fn.col('max_date_created').alias('max_date_created')),'left')

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...