Ich erstelle eine Funktion für Mappartitions, um das Maximum und Minimum pro Partition zu berechnen. Ich habe die Funktion in pyspark erstellt, aber ich kann sie nicht erfolgreich in scala übersetzen. Ich wende diese Funktion zweimal an und möchte im Ergebnis eine Zip-Funktion ausführen. Dies ist die errot, die ich bekomme:Spark (Scala) Problem Iteratoren
result.zip (res)
Typenkonflikt;
[error] found : org.apache.spark.rdd.RDD[(Int, Int)]
[error] required: scala.collection.GenIterable[?]
Hier können Sie meine Funktion in Python haben:
def minmaxInt(iterator):
firsttime = 0
min = 0
max = 0
for x in iterator:
if(x!= '' and x!='NULL' and x is not None):
y=int(x)
if (firsttime == 0):
min = y;
max = y;
firsttime = 1
else:
if y > max:
max = y
if y < min:
min = y
return (min, max)
Und hier mein Code in Scala
def minmaxInt(iterator: Iterator[String]) : Iterator[(Int,Int)]={
var firsttime = 0
var min = 0
var max = 0
var res=List[(Int,Int)]()
for(x <- iterator){
if(x!= "" && x!= null){
var y=x.toInt
if(firsttime == 0){
min = y
max = y
firsttime = 1}
else{
if (y > max){
max = y}
if (y < min){
min = y}
}
}
}
res.::=(min,max)
return res.iterator
}
Vielen Dank im Voraus
Update:
Dank für dein schnelle Antwort! Der Code ist großartig, aber ich habe immer noch Probleme mit dem Zip. Ich habe zweimal die letzten Code für rdd.mapPartitions und dann ausführen ich die Zip:
[error] found : org.apache.spark.rdd.RDD[(Int, Int)]
[error] required: scala.collection.GenIterable[?]
[error] result.zip(res)
einigen Kontext fehlt - der Fehler im Code zu sein scheint, die hier nicht dargestellt ist (es gibt keine Hinweise auf 'RDD's im Code, den Sie eingefügt) –
Dies ist, was ich mache, nur eine Spalte von einem CSV nehmen und die Minmax-Funktion anwenden. ' val file = sc.textFile (Pfad) val split = Datei.map (x => x.split (", ")) val col = split.map (x => x (0)) var Ergebnis = col.mapPartitions (minmaxInt) ... Später, die gleichen ... var res = col.mapPartitions (minmaxInt) result.zip (res) ' – Javier
keinen Code in Kommentare hinzufügen - [bearbeiten] (http://stackoverflow.com/posts/42067415/edit) die Post, die fehlenden Informationen –