Exception in thread "main"org.apache.spark.sql.AnalysisException: Resolved attribute(s)

3126 단어 경험 공유hadoop
업무가 특수하기 때문에 같은 df를 두 번 진행하면 다음과 같은 오류를 보고합니다.
Exception in thread "main" org.apache.spark.sql.AnalysisException: Resolved attribute(s) goods_name#1139 missing from order_id#498,goods_name#476 in operator !TypedFilter , interface org.apache.spark.sql.Row, [StructField(order_id,StringType,true), StructField(goods_name,StringType,true)], createexternalrow(order_id#498.toString, goods_name#1139.toString, StructField(order_id,StringType,true), StructField(goods_name,StringType,true)). Attribute(s) with the same name appear in the operation: goods_name. Please check if the right attribute(s) are used.;;
Join Inner
:- Project [txt_code#6, order_record_code#7, business_type#8, cust_id#9, net_cash_account#10, to_account_date#11, goods_name#476]
:  +- Join Inner, (order_code#569 = order_record_code#7)
:     :- LogicalRDD [txt_code#6, order_record_code#7, business_type#8, cust_id#9, net_cash_account#10, to_account_date#11], false
:     +- Join Inner, (order_record_code#770 = order_code#569)
:        :- Join Inner, (order_id#471 = id#568)
:        :  :- LogicalRDD [id#568, order_code#569], false
:        :  +- Project [order_id#471, goods_name#476, news_package#490, brand_package#494]
:        :     +- Join Inner, (order_id#471 = order_id#503)
:        :        :- Project [order_id#471, goods_name#476, news_package#490]
:        :        :  +- Join Inner, (order_id#471 = order_id#498)
:        :        :     :- TypedFilter , interface org.apache.spark.sql.Row, [StructField(order_id,StringType,true), StructField(goods_name,StringType,true)], createexternalrow(order_id#471.toString, goods_name#476.toString, StructField(order_id,StringType,true), StructField(goods_name,StringType,true))
:        :        :     :  +- Project [order_id#471, UDF(goods_name#472) AS goods_name#476]
:        :        :     :     +- TypedFilter , interface org.apache.spark.sql.Row, [StructField(order_id,StringType,true), StructField(goods_name,StringType,true)], createexternalrow(order_id#471.toString, goods_name#472.toString, StructField(order_id,StringType,true), StructField(goods_name,StringType,true))
:        :        :     :        +- LogicalRDD [order_id#471, goods_name#472], false

해결 방식: 두 번째 join을 진행하기 전에 열마다 별명을 따서 join에서 해결하면 됩니다.
    val tmpJoinDf = achievementDf.selectExpr("txt_code as txt_code2", "order_record_code as order_record_code2", "business_type as business_type2", "cust_id as cust_id2", "min_to_account_date", "groupCol").as("joinDf")

 val joinExprs = functions.col("joinDf.txt_code2") === functions.col("txt_code") && functions.col("joinDf.order_record_code2") === functions.col("order_record_code") && functions.col("joinDf.business_type2") === functions.col("business_type") && functions.col("joinDf.cust_id2") === functions.col("cust_id")
    result1Df = “ join df”.join(tmpJoinDf, joinExprs).select(fileldArr: _*)```

좋은 웹페이지 즐겨찾기