2014-11-03 64 views
0

我試圖運行一個簡單的地圖reduce操作TSV數據集,我對當我嘗試一個簡單的地圖操作時會出現什麼問題感到困惑。以下是我對地圖類的sample Word Count problem的修改。Hadoop中的TSV輸入Map Reduce

public static class Map extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable> { 
    private Text node = new Text(); 

    public void map(LongWritable key, Text value, OutputCollector<Text, IntWritable> output, Reporter reporter) throws IOException { 
     String line = value.toString(); 
     String tokens[] = line.split('t'); 
     node.set(tokens[1]); 
     int weight = Integer.parseInt(tokens[2]); 
     output.collect(node, new Writable(weight)); 

    } 
    } 

該輸入可以可視化爲具有三列的TSV文件。上面的代碼在行被分割爲標記的行中出現錯誤method.java.lang.String.split being not applicable。任何想法,我可能會出錯?

+1

嘗試使用:'line.split(「\ t」);'而不是'line.split('t')'。 – Ashrith 2014-11-03 18:15:33

回答

1

String tokens [] = line.split('t');

更改爲

字符串標記[] = line.split( '\噸');

0

String tokens[] = line.split('t');

它應該是:

String tokens[] = line.split("\t");

使用單引號是char類型,並會引發異常。