How to use groupByKey() on multiple RDDs?

How to use groupByKey() on multiple RDDs?



I have multiple RDDs with one common field CustomerId.


CustomerId



For eg:



debitcardRdd has data as (CustomerId, debitField1, debitField2, ......)


debitcardRdd


(CustomerId, debitField1, debitField2, ......)



creditcardRdd has data as (CustomerId, creditField1, creditField2, ....)


creditcardRdd


(CustomerId, creditField1, creditField2, ....)



netbankingRdd has data as (CustomerId, nbankingField1, nbankingField2, ....)


netbankingRdd


(CustomerId, nbankingField1, nbankingField2, ....)



We perform different transformations on each individual rdd, however we need to perform a transformation on the data from all the 3 rdds by grouping CustomerId.


CustomerId



Example: (CustomerId,debitFiedl1,creditField2,bankingField1,....)


(CustomerId,debitFiedl1,creditField2,bankingField1,....)



Is there any way we can group the data from all RDDs based on same key.



Note: In Apache Beam it can be done by using coGroupByKey, just checking if there is such alternative available in spark.


coGroupByKey






I clearly mentioned what was expected, it has nothing to do with sample data. Not sure why this was down voted.

– Abhinay
Sep 11 '18 at 14:30






I think you could join all the rdds and then group it.

– K S Nidhin
Sep 11 '18 at 14:33






Not sure it's equivalent to Apache Beam's coGroupByKey, Spark RDD[K, V] does have cogroup. Here's a relevant SO link.

– Leo C
Sep 11 '18 at 16:47



RDD[K, V]




2 Answers
2



Just cogroup


cogroup


debitcardRdd.keyBy(_.CustomerId).cogroup(
creditcardRdd.keyBy(_.CustomerId),
netbankingRdd.keyBy(_.CustomerId)
)



In contrast to the below, the .keyBy is not imho actually required here and we note that cogroup - not well described can extend to n RDDs.


val rddREScogX = rdd1.cogroup(rdd2,rdd3,rddn, ...)



Points should go to the first answer.



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

PHP code is not being executed, instead code shows on the page

Administrative divisions of China