Created
December 19, 2012 01:37
-
-
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
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
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