“缺少已解决的属性";在pySpark上执行加入时 [英] "resolved attribute(s) missing" when performing join on pySpark

查看:246
本文介绍了“缺少已解决的属性";在pySpark上执行加入时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下两个pySpark数据框:

I have the following two pySpark dataframe:

> df_lag_pre.columns
['date','sku','name','country','ccy_code','quantity','usd_price','usd_lag','lag_quantity']

> df_unmatched.columns
['alt_sku', 'alt_lag_quantity', 'country', 'ccy_code', 'name', 'usd_price']

现在我想将它们加入公共列,所以我尝试以下操作:

Now I want to join them on common columns, so I try the following:

> df_lag_pre.join(df_unmatched, on=['name','country','ccy_code','usd_price'])

我收到以下错误消息:

AnalysisException: u'resolved attribute(s) price#3424 missing from country#3443,month#801,price#808,category#803,subcategory#804,page#805,date#280,link#809,name#806,quantity#807,ccy_code#3439,sku#3004,day#802 in operator !EvaluatePython PythonUDF#<lambda>(ccy_code#3439,price#3424), pythonUDF#811: string;'

出现此错误的某些列(例如价格)是从其构建df_lag的另一个数据框的一部分.我找不到任何有关如何解释此消息的信息,因此将不胜感激.

Some of the columns that show up on this error, such as price, were part of another dataframe from which df_lag was built from. I can't find any info on how to interpret this message, so any help would be greatly appreciated.

推荐答案

您可以在pyspark中以这种方式执行连接,请查看这是否对您有用:

You can perform join this way in pyspark, Please see if this is useful for you:

df_lag_pre.alias("df1")
df_unmatched.alias("df2")
join_both = df1.join(df2, (col("df1.name") == col("df2.name")) & (col("df1.country") == col("df2.country")) & (col("df1.ccy_code") == col("df2.ccy_code")) & (col("df1.usd_price") == col("df2.usd_price")), 'inner')

更新:如果您收到未定义的错误,请在下面的导入中使用

Update: If you are getting col not defined error, please use below import

from pyspark.sql.functions import col

这篇关于“缺少已解决的属性";在pySpark上执行加入时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆