【问题标题】:Pyspark self-join with error "Resolved attribute(s) missing"Pyspark 自联接错误“缺少已解决的属性”
【发布时间】:2019-07-02 18:24:08
【问题描述】:

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

【问题讨论】:

    标签: python python-3.x pyspark apache-spark-2.3


    【解决方案1】:

    我在这里找到了一个 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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-19
      • 2013-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-24
      相关资源
      最近更新 更多