2014-04-13 3 views
2

와 나는 읽고 this 자습서를 구현했다. 마지막으로 Mapper, Reducer 및 드라이버라는 세 가지 클래스를 구현합니다. 세 개의 클래스 모두에 대해 웹 페이지에 제공된 정확한 코드를 복사했습니다. 그러나이 오류 다음은 사라지지 않았다 -하둡 통합 이클립스

***************** 매퍼 클래스 **************** *******************************************

import java.io.IOException; 
import java.util.StringTokenizer; 

import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.LongWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.io.Writable; 
import org.apache.hadoop.io.WritableComparable; 
import org.apache.hadoop.mapred.MapReduceBase; 
import org.apache.hadoop.mapred.Mapper; 
import org.apache.hadoop.mapred.OutputCollector; 
import org.apache.hadoop.mapred.Reporter; 

public class WordCountMapper extends MapReduceBase //////Here WordCountMapper was underlined as error source by Eclipse 
    implements Mapper<LongWritable, Text, Text, IntWritable> { 

    private final IntWritable one = new IntWritable(1); 
    private Text word = new Text(); 

    public void map(WritableComparable key, Writable value, 
     OutputCollector output, Reporter reporter) throws IOException { 

    String line = value.toString(); 
    StringTokenizer itr = new StringTokenizer(line.toLowerCase()); 
    while(itr.hasMoreTokens()) { 
     word.set(itr.nextToken()); 
     output.collect(word, one); 
    } 
    } 
} 

오류 :

The type WordCountMapper must implement the inherited abstract method 
Mapper<LongWritable,Text,Text,IntWritable>.map(LongWritable, Text, 
OutputCollector<Text,IntWritable>, Reporter) 

********************** 드라이버 클래스 (WordCount.java) ********

*************************

import org.apache.hadoop.fs.Path; 
import org.apache.hadoop.io.IntWritable; 
import org.apache.hadoop.io.Text; 
import org.apache.hadoop.mapred.FileInputFormat; 
import org.apache.hadoop.mapred.FileOutputFormat; 
import org.apache.hadoop.mapred.JobClient; 
import org.apache.hadoop.mapred.JobConf; 

public class WordCount { 

    public static void main(String[] args) { 
    JobClient client = new JobClient(); 
    JobConf conf = new JobConf(WordCount.class); 

    // specify output types 
    conf.setOutputKeyClass(Text.class); 
    conf.setOutputValueClass(IntWritable.class); 

    // specify input and output dirs 
    FileInputPath.addInputPath(conf, new Path("input")); //////////FileInputPath was underlined 
    FileOutputPath.addOutputPath(conf, new Path("output")); ////////FileOutputPath as underlined 

    // specify a mapper 
    conf.setMapperClass(WordCountMapper.class); 

    // specify a reducer 
    conf.setReducerClass(WordCountReducer.class); 
    conf.setCombinerClass(WordCountReducer.class); 

    client.setConf(conf); 
    try { 
     JobClient.runJob(conf); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
    } 
} 

오류 :

1. FileInputPath cannot be resolved 
2. FileOutputPath cannot be resolved 

누군가 문제가 무엇인지 말해 줄 수 있습니까? 미리 감사드립니다.

답변

2

사용 org.apache.hadoop.mapred.FileInputFormat, org.apache.hadoop.mapred.FileOutputFormat 다음과 같이 코드를 수정 :

// specify input and output dirs 
    FileInputFormat.addInputPath(conf, new Path("input")); 
    FileOutputFormat.addOutputPath(conf, new Path("output")); 
4

Sachinjose 내가 코드를 변경하는 경우, 두 번째 오류가 해결되었다 말했듯이 : -

FileInputFormat.addInputPath(conf, new Path("input")); 
    FileOutputFormat.setOutputPath(conf, new Path("output")); 

는 또한 첫 번째 오류가 this 예제에서 해결됨 (user2357112의 답안을 복사 중입니다) : -

귀하는 유형 pa rameters. Mapper는 일반적인 인터페이스입니다. 입력 및 출력 키 및 값 유형에 대한 유형 매개 변수로 매개 변수화되었습니다. 다음 코드에서 K1, V1, K2 및 V2를 필요한 유형으로 채 웁니다.

public class WordMapper extends MapReduceBase implements Mapper<K1, V1, K2, V2> { 
    public void map(K1 key, 
        V1 value, 
        OutputCollector<K2, V2> output, 
        Reporter reporter) 
      throws IOException { 
     whatever(); 
    } 
}