Ich habe zwei Schlüsselwert Pair rdd's A and B
, Daten wieIteration in Cogrouped zweiten Tupel CompactBuffer
A={(1,(1,john,CA)),
(2,(2,steve,NY)),
(3,(3,jonny,AL)),
(4,(4,Evan,AK)),
(5,(5,Tommy,AZ))}
B={(1,(1,john,WA)),
(1,(1,john,FL)),
(1,(1,john,GA)),
(2,(2,steve,NY)),
(3,(3,jonny,AL)),
(4,(4,Evan,AK)),
(5,(5,Tommy,AZ))}
Rdd B
hat drei Werte für den Schlüssel 1
so während der Anwendung cogroup
c = A.cogroup(B).filter { x => ((x._2._1) != (x._2._2)) }.collect() we get
c = {(1,CompactBuffer(1,john,CA),CompactBuffer(1,john,WA,1,john,FL,1,john,GA)}
Sammeln zwei CompactBuffers
sieht in zwei Variablen wie unten
d = c.map(tuple =>(tuple._2._1.mkString("")))
e = c.map(tuple =>(tuple._2._2.mkString("")))
Iterieren d
und e
wie unten
for(x <-d)
{
for(y <-e){
println(x +" source and destination "+ y)
}
}
Erwartete Ausgabe
1,john,CA source and destination 1,john,WA
1,john,CA source and destination 1,john,FL
1,john,CA source and destination 1,john,GA
Ausgang empfangen
1,john,CA source and destination 1,john,WA,1,john,FL,1,john,GA
Was soll ich für Iterieren ändern die Second Tuple elements i.e Second Compactbuffer()
Bitte lassen Sie mich wissen, wenn Sie Zweifel oder Klärung in Frage haben.
Die Länge des Arrays, das von 'e = c.map (tuple => (tuple._2._2.mkString (" ")))' 'zurückgegeben wird, wäre' 1', weil Sie 'mkString' verwenden. Also haben "d" und "e" jeweils nur einen Wert. – philantrovert
Wenn ich 'mkString() '' '' '' '' ''' '' '' '' '' '' '' '' '' Quelle und Ziel CompactBuffer (1, John, WA, 1, John, FL, 1, John, GA) ' – Vignesh
Tr 'val e = c.map (tuple => tuple._2._2) .flatMap (identity) 'und selbe für' d' und dann starte deine for loops – philantrovert