spark 集合交集差集运算

intersect except是spark提供的集合差集运算, 但是要求参与运算的两个dataframe,有相同的data Schema。

如果我想从 集合1(attribute1, attribute2, attribute3)求 attribute2 出现在另一个集合2(attribute2, attribute4, attribute5)里的所有行

则intersect 完全无效, 我刚接触spark没多久, 只好就绕了一下路。 实践如下。 

multiple_orders$forJoin = multiple_orders$presentee_mobile
multiple_orders$presentee_mobile=NULL
order_nonFastCar <- join(order_nonFastCar, multiple_orders, order_nonFastCar$presentee_mobile==multiple_orders$forJoin, "left_outer")
order_nonFastCar= filter(order_nonFastCar, "forJoin is null")
order_nonFastCar$forJoin=NULL

把属性改一下名, 是因为order_nonFastCar里也有presentee_mobile这个属性列。 如果不改名, join之后无法通过filter求交集

原文地址:https://www.cnblogs.com/realzjx/p/5716292.html