2014-10-30 31 views
0

這是我的輸入文件(custs.txt):映射器沒有產生預期的結果

1002 | surender | 23
1003 | Rahja | 24

這是我的程序:

主營:

public class ReduceSideJoinMain { 

/** 
* @param args 
* @throws IOException 
* @throws ClassNotFoundException 
* @throws InterruptedException 
*/ 
public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException { 
    Configuration conf = new Configuration(); 
    JobConf config = new JobConf(); 
    config.setQueueName("omega"); 

    Job job = new Job(config,"word count"); 

    job.setJarByClass(ReduceSideJoinMain.class); 

    Path inputFilePath1 = new Path(args[0]); 
    Path outputFilePath2 = new Path(args[1]); 

    //MultipleInputs.addInputPath(job, inputFilePath1, TextInputFormat.class,CustMapper.class); 
    //MultipleInputs.addInputPath(job, inputFilePath2, TextInputFormat.class,TxnsMapper.class); 

    FileInputFormat.addInputPath(job, inputFilePath1); 
    FileOutputFormat.setOutputPath(job, outputFilePath2); 

    job.setInputFormatClass(TextInputFormat.class); 
    job.setOutputFormatClass(TextOutputFormat.class); 

    job.setMapperClass(CustMapper.class); 
    //job.setReducerClass(ReduceJoinMapper.class); 

    job.setMapOutputKeyClass(Text.class); 
    job.setMapOutputValueClass(Text.class); 

    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(Text.class); 

    System.exit(job.waitForCompletion(true) ? 0 : 1); 

} 

} 

映射

public class CustMapper extends Mapper<LongWritable,Text,Text,Text> 
{ 
public static IntWritable one = new IntWritable(1); 

    protected void map(LongWritable key, Text value, Context context) throws java.io.IOException,java.lang.InterruptedException 
    { 

    String line = value.toString(); 


    String arr[]= line.split("|"); 
    context.write(new Text(arr[0]), new Text(arr[1])); 

    } 
} 

我得到下面的輸出,這是錯誤的:

 1 
     1 

我期待的輸出爲:

1002 surender 
1003 Rahja 

爲什麼不給預期的產出? Split方法有問題嗎?

回答

1

使用String arr[] = line.split("\\|");

+0

完美..我嘗試過了,它得到了解決,我也我才知道什麼是根本原因。非常感謝 – 2014-10-30 14:14:29

相關問題