假设我有这些案例类
case class Employee(id: Long, proj_id: Long, office_id: Long, salary: Long)
case class Renumeration(id: Long, amount: Long)
我想更新Employee基于Renumeration使用 Spark的集合
val right: Dataset[Renumeration] = ???
val left: Dataset[Employee] = ???
left.joinWith(broadcast(right),left("proj_id") === right("id"),"leftouter")
.map { case(left,right) => updateProj(left,right) }
.joinWith(broadcast(right),left("office_id") === right("id"),"leftouter")
.map { case(left,right) => updateOffice(left,right) }
def updateProj(emp: Employee; ren: Renumeration): Employee = //business logic
def updateOffice(emp: Employee; ren: Renumeration): Employee = //business logic
第一个join并且map有效,但是当我介绍第二个joinSpark 时未能解决该id列并显示了这些。
org.apache.spark.sql.AnalysisException: Resolved attribute(s) office_id#42L missing from id#114L,salary#117L,id#34L,amount#35L,proj_id#115L,office_id#116L in operator !Join LeftOuter, (office_id#42L = id#34L). Attribute(s) with the same name appear in the operation: office_id. Please check if the right attribute(s) are used.;;
!Join LeftOuter, (office_id#42L = id#34L)
:- SerializeFromObject [assertnotnull(assertnotnull(input[0, Employee, true])).id AS id#114L, assertnotnull(assertnotnull(input[0, Employee, true])).proj_id AS proj_id#115L, assertnotnull(assertnotnull(input[0, Employee, true])).office_id AS office_id#116L, assertnotnull(assertnotnull(input[0, Employee, true])).salary AS salary#117L]
: +- MapElements <function1>, class scala.Tuple2, [StructField(_1,StructType(StructField(id,LongType,false), StructField(proj_id,LongType,false), StructField(office_id,LongType,false), StructField(salary,LongType,false)),true), StructField(_2,StructType(StructField(id,LongType,false), StructField(amount,LongType,false)),true)], obj#113: Employee
: +- DeserializeToObject newInstance(class scala.Tuple2), obj#112: scala.Tuple2
: +- Join LeftOuter, (_1#103.proj_id = _2#104.id)
: :- Project [named_struct(id, id#40L, proj_id, proj_id#41L, office_id, office_id#42L, salary, salary#43L) AS _1#103]
: : +- LocalRelation <empty>, [id#40L, proj_id#41L, office_id#42L, salary#43L]
: +- Project [named_struct(id, id#34L, amount, amount#35L) AS _2#104]
: +- ResolvedHint (broadcast)
: +- LocalRelation <empty>, [id#34L, amount#35L]
+- ResolvedHint (broadcast)
+- LocalRelation <empty>, [id#34L, amount#35L]
知道为什么 Spark 无法解析列,即使我已经使用了 typed Dataset?如果可能的话,我应该怎么做才能完成这项工作?