Skip to content

Instantly share code, notes, and snippets.

@ahoy-jon
Created October 14, 2016 15:44
Show Gist options
  • Save ahoy-jon/ba0277ae8596a416d3477fe0d7b51031 to your computer and use it in GitHub Desktop.
Save ahoy-jon/ba0277ae8596a416d3477fe0d7b51031 to your computer and use it in GitHub Desktop.
val result = stRdd.groupBy(_.id).map({
case (ig, vars) =>
val svars: Seq[SomeTable] = vars.toSeq.sortBy(_.updateAt).reverse
def ex(f: SomeTable => String): String = svars.map(f).find(_ != null).orNull
def ex2(f: SomeTable => String): (String, Timestamp) = {
svars.map(x => (f(x), x.updateAt)).find(_._1 != null).getOrElse((null, null))
}
def max[T: Ordering](f: SomeTable => T): T = svars.map(f).max
val (ex1, ex_dt) = ex2(_.value2)
(SomeTable(id = ig, value1 = ex(_.value1),
value2 = ex1,
updateAt = max(_.updateAt),
value3 = max(_.value3),
value4 = ex(_.value4)), ex_dt)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment