簡體   English   中英

Pyspark自聯接,錯誤為“缺少已解決的屬性”

[英]Pyspark self-join with error “Resolved attribute(s) missing”

在執行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')

使用像波紋管這樣的數據框別名也不起作用,並且會出現相同的錯誤消息:

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

我在SPARK-14948上找到了Java解決方法,對於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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM