LOW LOW HIGH LOW LOW
LOW HIGH MOD LOW LOW
HIGH LOW HIGH HIGH HIGH
LOW LOW LOW LOW LOW
. . . . .
. . . . .
的輸入文件,我想有結果如下:
Genuine
Moderate
Not_genuine
Genuine
.
.
爲此,我需要解析一行並在每行上應用WordCount,然後根據no。的高或低計數我會指定所需的結果。 通過使用Stringtokenizer
所有線路都考慮在內,也split method
沒有得到線(\n)
結束。是有反正我可以通過這個問題繼續進行,並得到想要的答案
CODE做了MAPPER
這裏,我試圖用的\n
public void map(LongWritable key, Text value, Context context)
throws IOException, InterruptedException {
String line = value.toString();
StringTokenizer tokenizer = new StringTokenizer(line);
while (tokenizer.hasMoreTokens()) {
if(tokenizer.equals("\n")){
System.out.println("Line ends here");
Log log = LogFactory.getLog(getClass());
log.info("Line ends here");
}
word.set(tokenizer.nextToken());
context.write(word, one);
}
你能否提供你的代碼mcve? (或者你使用嵌入式jar的時候執行的命令) – fxm 2015-03-13 15:27:56
我試過了基本的wordCount MR作業來掃描,但是它會掃描整個輸入文件(我想掃描一行並生成輸出)。我甚至嘗試過使用NLineInputformat但不能設置一個相同的映射器。 – Anush 2015-03-13 15:44:35
@TAKZO你的新行有問題嗎?如果您使用textinputformat,它會在檢測到換行符時自動採用新行。你可以用split方法去分隔一些分隔符。 – 221B 2015-03-13 16:42:25