gpt4 book ai didi

python - Pyspark 自连接错误 "Resolved attribute(s) missing"

转载 作者:行者123 更新时间:2023-12-02 16:54:52 25 4
gpt4 key购买 nike

在执行 pyspark 数据帧自连接时,我收到一条错误消息:

Py4JJavaError: An error occurred while calling o1595.join.
: org.apache.spark.sql.AnalysisException: Resolved attribute(s) un_val#5997 missing from day#290,item_listed#281,filename#286 in operator !Project [...]. Attribute(s) with the same name appear in the operation: un_val. Please check if the right attribute(s) are used.;;

这是一个简单的数据帧自连接,如下所示,工作正常,但在对数据帧进行一些操作(如添加列或与其他数据帧连接)后,会出现上述错误。

df.join(df,on='item_listed')

使用像 bellow 这样的数据框别名也不起作用,并且会出现相同的错误消息:

df.alias('A').join(df.alias('B'), col('A.my_id') == col('B.my_id'))

最佳答案

我在这里找到了 Java 解决方法 SPARK-14948对于 pyspark 是这样的:

#Add a "_r" suffix to column names array
newcols = [c + '_r' for c in df.columns]

#clone the dataframe with columns renamed
df2 = df.toDF(*newcols)

#self-join
df.join(df2,df.my_column == df2.my_column_r)

关于python - Pyspark 自连接错误 "Resolved attribute(s) missing",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56858203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com