Skip to content

Instantly share code, notes, and snippets.

@rweald
Created December 19, 2012 01:37
Show Gist options
  • Save rweald/4333687 to your computer and use it in GitHub Desktop.
Save rweald/4333687 to your computer and use it in GitHub Desktop.
Sample scalding job that reads a line of JSON and parses out 1 field
import com.twitter.scalding._
import scala.util.parsing.json._
class ParseJsonJob(args: Args) extends Job(args) {
TextLine(args("input"))
.map(('line) -> ('parseStatus, 'uri)) {
line: String => {
JSON.parseFull(line) match {
case Some(data: Map[String, String]) => ("success", data("uri"))
case None => ("failed", "")
}
}
}
.filter('parseStatus) { status: String => status != "failed" }
.project('uri)
.write(Tsv(args("output")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment