Spark AggregateByKey From pySpark to Scala -


i transferring code on scala , had function in pyspark have little clue on how translate on scala. can , provide explanation? pyspark looks this:

.aggregatebykey((0.0, 0.0, 0.0),                          lambda (sum, sum2, count), value: (sum + value, sum2 + value**2, count+1.0),                          lambda (suma, sum2a, counta), (sumb, sum2b, countb): (suma + sumb, sum2a + sum2b, counta + countb)) 

edit: have far is:

val datasusrdd = numfilterrdd.aggregatebykey((0,0,0), (sum, sum2, count) => 

but having trouble understanding how write in scala because of group of functions being designating value group of actions (sum + value, etc). second aggregating functions proper syntax. hard coherently state troubles in scenario. more not understanding of scala , when use brackets, vs parentheses, vs, comma

as @paul suggests using named functions might make understanding whats going on bit simpler.

val initialvalue = (0.0,0.0,0.0) def seqop(u: (double, double, double), v: double) = (u._1 + v, u._2 + v*v, u._3 + 1) def combop(u1: (double, double, double),  u2: (double, double, double)) = (u1._1 + u2._1, u1._2 + u2._2, u1._3 + u2._3) rdd.aggregatebykey(initialvalue)(seqop, combop) 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -