Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Last active October 14, 2016 14:26
Show Gist options
  • Save ahoy-jon/90a5fc468aa90fce72656ae2249640e9 to your computer and use it in GitHub Desktop.
Save ahoy-jon/90a5fc468aa90fce72656ae2249640e9 to your computer and use it in GitHub Desktop.
BlogBetterUADF
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