Last active
October 14, 2016 14:26
-
-
Save ahoy-jon/90a5fc468aa90fce72656ae2249640e9 to your computer and use it in GitHub Desktop.
BlogBetterUADF
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
val stRdd: RDD[SomeTable] = ??? | |
val result: RDD[SomeTable] = stRdd.groupBy(_.id).map({ | |
case (ig, vars) => | |
//Tri par date à l'intérieur du group | |
val svars: Seq[SomeTable] = vars.toSeq.sortBy(_.updateAt).reverse | |
//Définition de la fonction pour trouver le premier attribut non null de SomeTable | |
def ex(f: SomeTable => String): String = svars.map(f).find(_ != null).orNull | |
//Définition de max pour un attribut de SomeTable | |
def max[T: Ordering](f: SomeTable => T): T = svars.map(f).max | |
SomeTable(id = ig, | |
value1 = ex(_.value1), | |
value2 = ex(_.value2), | |
updateAt = max(_.updateAt), | |
value3 = max(_.value3), | |
value4 = ex(_.value4))}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment