2014-10-22 2 views
0

MapReduce를 처음 사용했습니다. 여기에 내 질문이있다. HDFS에서reduce()는 reduce (Text, Text) 만 허용 할 수 있습니까?

:

은 File2.txt :

2012-3-1 a 
2012-3-2 b 
2012-3-3 c 
2012-3-4 d 
2012-3-5 a 
2012-3-6 b 
2012-3-7 c 
2012-3-3 c 

와 file2.txt :

2012-3-1 b 
2012-3-2 a 
2012-3-3 b 
2012-3-4 d 
2012-3-5 a 
2012-3-6 c 
2012-3-7 d 
2012-3-3 c 

내가 데이터를 실행 // centmaster/입력 디렉토리, 나는이 개 파일이 중복 제거 MapReduce 코드 :

package Hadoop_for_jar; 
import java.io.IOException; 
import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Job; 
import org.apache.hadoop.mapreduce.Mapper; 
import org.apache.hadoop.mapreduce.Reducer; 
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 
import org.apache.hadoop.util.GenericOptionsParser; 

public class Dedup2 { 

    public static class Map extends Mapper<Object,Text,Text,Text>{ 
     private static Text line=new Text(); 
     public void map(Object key,Text value,Context context) 
       throws IOException,InterruptedException{ 
      line=value; 
      context.write(line, new Text("")); 
     } 

    } 

    public static class Reduce extends Reducer<Text,Text,Text,Text>{ 
     public void reduce(Text key,Iterable<Text> values,Context context) 
       throws IOException,InterruptedException{ 
      context.write(key, new Text("")); 
     } 
    } 

    public static void main(String[] args) throws Exception{ 
     Configuration conf = new Configuration(); 
     System.setProperty("HADOOP_USER_NAME", "root"); 
     String[] otherArgs = {"hdfs://centmaster:9000/input", "hdfs://centmaster:9000/output/debup1"}; 
     Job job = new Job(conf, "Data Deduplication"); 
     job.setJarByClass(Dedup.class); 

     job.setMapperClass(Map.class); 
     job.setCombinerClass(Reduce.class); 
     job.setReducerClass(Reduce.class); 

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

     FileInputFormat.addInputPath(job, new Path(otherArgs[0])); 
     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); 
     System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 
} 

성공적으로 실행됩니다. 결과는 다음과 같습니다

2012-3-1 a 
2012-3-1 b 
2012-3-2 a 
2012-3-2 b 
2012-3-3 b 
2012-3-3 c 
2012-3-4 d 
2012-3-5 a 
2012-3-6 b 
2012-3-6 c 
2012-3-7 c 
2012-3-7 d 

지금, 나는 감속기는 매퍼의 출력 감속기의 (키, 값)의 입력 값을 사용하지 않는, 생각하고 있어요.

이 프로그램에는 쓸모가 없습니다. Text를 IntWritable로 바꾸고 싶습니다. 그리고 같은 결과를 얻길 바랍니다. 그래서,

는 다음과 같이 변경했다 :

package Hadoop_for_jar; 
import java.io.IOException; 
import org.apache.hadoop.conf.Configuration; 
import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapreduce.Job; 
import org.apache.hadoop.mapreduce.Mapper; 
import org.apache.hadoop.mapreduce.Reducer; 
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat; 
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat; 
import org.apache.hadoop.util.GenericOptionsParser; 

public class Dedup2 { 

    public static class Map extends Mapper<Object,Text,Text,IntWritable>{ //Change Text to IntWritable 
     private static Text line=new Text(); 
     public void map(Object key,Text value,Context context) 
       throws IOException,InterruptedException{ 
      line=value; 
      context.write(line, new IntWritable(0)); //Change Text("") to IntWritable(0) 
     } 

    } 

    public static class Reduce extends Reducer<Text,IntWritable,Text,Text>{ //Change Text to IntWritable 
     public void reduce(Text key,Iterable<IntWritable> values,Context context) //Change Text to IntWritable 
       throws IOException,InterruptedException{ 
      context.write(key, new Text("")); 
     } 

    } 

    public static void main(String[] args) throws Exception{ 
     Configuration conf = new Configuration(); 
     System.setProperty("HADOOP_USER_NAME", "root"); 
     String[] otherArgs = {"hdfs://centmaster:9000/input", "hdfs://centmaster:9000/output/debup2"}; 
     Job job = new Job(conf, "Data Deduplication"); 
     job.setJarByClass(Dedup2.class); 

     job.setMapperClass(Map.class); 
     job.setCombinerClass(Reduce.class); 
     job.setReducerClass(Reduce.class); 

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

     FileInputFormat.addInputPath(job, new Path(otherArgs[0])); 
     FileOutputFormat.setOutputPath(job, new Path(otherArgs[1])); 
     System.exit(job.waitForCompletion(true) ? 0 : 1); 
    } 
} 

을 그리고/출력/debup2 디렉토리가있다. 그러나 디렉토리가 비어 있습니다. 내 가정은 틀렸다. 그래서, 제 질문은 : Reducer()가 입력 (텍스트, 텍스트) 만 수락합니까? 감사합니다.

답변

관련 문제