spark 集合交集差集运算

本文介绍了使用Spark进行集合差集运算的具体实践方法。当两个DataFrame的schema不完全相同时,如何通过重命名属性和使用特定的连接类型来实现差集操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值