0
給定RDD[(A, B)]
,其中A
和B
之間存在多對多關係,如何將關係的交集分組?在Spark中合併相交多對多關係
即,如果可以通過一個或多個B
s從一個A
到另一個A
繪製關係,則應該對它們進行分組。同樣,B
s可以通過A
s進行分組。
例如,集合:
(1, 'a')
(2, 'a')
(2, 'b')
(1, 'c')
(3, 'f')
(4, 'f')
(5, 'g')
應組成
([1,2], ['a','b','c'])
([3,4], ['f'])
([5], ['g'])
我可以使用groupByKey
獲得
(1, ['a', 'c'])
(2, ['a', 'b'])
(3, ['f'])
(4, ['f'])
(5, ['g'])
並且還
('a', [1, 2])
('b', [2])
('c', [1])
('f', [3,4])
('g', [5])
但我不知道在哪裏把它從這裏開始。
RDD不支持這樣的行動在箱子外面!我認爲,第一步是正確的。在任何groupBy之後,您需要根據需要對列表進行摺疊。 – rakesh