Scalding是一个Scala库简化了HadoopMapReduce作业开发。基于Cascading构建。Scalding跟Pig类似,但提供更紧密的Scala集成。
Hadoop是一个统计词(countingwords)的分布式系统。这里看Scalding如何实现统计词:
package com.twitter.scalding.examplesimport com.twitter.scalding._class WordCountJob(args: Args) extends Job(args) { TypedPipe.from(TextLine(args("input"))) .flatMap { line => tokenize(line) } .groupBy { word => word } // use each word for a key .size // in each group, get the size .write(TypedTsv[(String, Long)](args("output"))) // Split a piece of text into individual words. def tokenize(text : String) : Array[String] = { // Lowercase each word and remove punctuation. text.toLowerCase.replaceAll("[^a-zA-Z0-9\\s]", "").split("\\s+") }}
评论