2012-07-07 4 views
0

나는 하둡에게 0.18.3하둡 ClassCastException이

java.lang.ClassCastException가를 사용하여 다음과 같은 오류가 발생 : org.apache.hadoop.io.Text이 org.apache.hadoop.io.DoubleWritable

캐스트 할 수없는 내가 일을 설정

public class HadoopMapper extends MapReduceBase implements Mapper<Text,DoubleWritable,Text,DoubleWritable> { 
// The Karmasphere Studio Workflow Log displays logging from Apache Commons Logging, for example: 
// private static final Log LOG = LogFactory.getLog("HadoopMapper"); 

@Override 
public void map(Text key, DoubleWritable value, OutputCollector<Text, DoubleWritable> output, Reporter reporter) 
     throws IOException { 
//  throw new UnsupportedOperationException("Not supported yet."); 
    Random generator = new Random(); 
    int i; 

    final int iter = 100000; 

    for (i =0; i < iter; i++) 
    { 
    double x = generator.nextDouble(); 
    double y = generator.nextDouble(); 

    double z; 

    z = x*x + y*y; 

    if (z <= 1){ 
     output.collect(new Text("VALUE"), new DoubleWritable(1)); 
    }else{ 
     output.collect(new Text ("VALUE"), new DoubleWritable(0)); 
    } 
    } 


    } 
} 

및 감속기 클래스

public class HadoopReducer extends MapReduceBase implements Reducer<Text,DoubleWritable,Text,DoubleWritable> { 
// The Karmasphere Studio Workflow Log displays logging from Apache Commons Logging, for example: 
// private static final Log LOG = LogFactory.getLog("HadoopReducer"); 

@Override 
public void reduce(Text key, Iterator<DoubleWritable> value, OutputCollector<Text, DoubleWritable> output, Reporter reporter) 
     throws IOException { 
    // TODO code reducer logic here 
//  throw new UnsupportedOperationException("Not supported yet."); 

    double pi = 0; 
    double inside = 0; 
    double outside = 0; 

    while (value.hasNext()) 
    { 
    if (value.next().get() == (long)1) 
    inside++; 
    else 
    outside++; 
    } 

    pi = (4*inside)/(inside + outside); 

    output.collect(new Text ("pi"), new DoubleWritable(pi)); 
    } 
} 

로 :로

내 매퍼를 정의 로 conf의 : 나는 일치하고 KeyValueTextInputFormat.class conf.setInputFormat (KeyValueTextInputFormat.class)에서 Inputformat을 찾을 수

public static void initJobConf(JobConf conf) { 
// Generating code using Karmasphere Protocol for Hadoop 0.18 
// CG_GLOBAL 

// CG_INPUT_HIDDEN 
    conf.setInputFormat(KeyValueTextInputFormat.class); 
// CG_MAPPER_HIDDEN 
conf.setMapperClass(HadoopMapper.class); 

// CG_MAPPER 

// CG_PARTITIONER_HIDDEN 
conf.setPartitionerClass(org.apache.hadoop.mapred.lib.HashPartitioner.class); 

// CG_PARTITIONER 

// CG_COMPARATOR_HIDDEN 
conf.setOutputKeyComparatorClass(org.apache.hadoop.io.Text.Comparator.class); 

// CG_COMPARATOR 

// CG_COMBINER_HIDDEN 

// CG_REDUCER_HIDDEN 
conf.setReducerClass(HadoopReducer.class); 

// CG_REDUCER 
    conf.setNumReduceTasks(1); 

    // CG_OUTPUT_HIDDEN 
    conf.setOutputKeyClass(Text.class); 
    conf.setOutputValueClass(DoubleWritable.class); 
    // CG_OUTPUT 

    // Others 
    } 

은, 그래서 어떻게 다루는? 서브 클래스를 만들 수 있습니까? 예를 들어 도와 줄 수 있습니까? 감사합니다.

+0

그래서 트릭을 했나요? – Razvan

답변

0

KeyValueTextInputFormat은 입력란에 텍스트 키와 SEPARATOR_CHARACTER (기본 탭)로 구분 된 텍스트 값을 입력해야합니다. DoubleWritable로 변환하려고 시도하고 있습니다. 기본적으로 불가능합니다. 이에 따라 매퍼 < 텍스트, 텍스트, 텍스트, DoubleWritable>

및지도 방법 다음 직접 두배로 텍스트를 변환 :

그래서, 당신에게 매퍼를 수정합니다.

+0

비슷한 방식으로 출력 형식을 처리해야합니다! – Razvan