Created
April 2, 2015 21:51
-
-
Save granthenke/d5414936a285a294dd76 to your computer and use it in GitHub Desktop.
Scala Scratch Pad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class MeanM(sum: Double, count: Long) { | |
def +(that: MeanM): MeanM = { | |
new MeanM(this.sum + that.sum, this.count + that.count) | |
} | |
def mean = sum / count.toDouble | |
} | |
val data = List(("cust1", 1.0),("cust1", 5.0),("cust2", 6.0)) | |
val dataRDD = sc.makeRDD(data) | |
dataRDD.aggregateByKey(MeanM(0,0))(_ + MeanM(_,1), _ + _).mapValues(_.mean) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment