Created
October 23, 2017 12:12
-
-
Save softberries/5a8f631fcc86a3deb53e8449e209cf0d to your computer and use it in GitHub Desktop.
Scalding Job Definition
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
class AgeCounterJob(args: Args) extends Job(args) { | |
val lines: TypedPipe[String] = TypedPipe.from(TextLine(args("input"))) | |
val tokens: TypedPipe[Token] = lines.flatMap(f => xmlToToken(f)) | |
val byAge = tokens.groupBy(_.age) | |
byAge.size | |
.write(TypedTsv[(Int, Long)](args("output"))) | |
def xmlToToken(content: String): Option[Token] = { | |
val namePattern = "DisplayName=\"(.*)\"".r | |
val agePattern = "Age=\"([0-9]+)\"".r | |
for { | |
name <- namePattern.findFirstMatchIn(content).map(m => m.group(1)) | |
age <- agePattern.findFirstMatchIn(content).map(m => m.group(1)) | |
} yield Token(name, age.toInt) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment