2016-07-30 23 views
0

在試圖評估Spark重新使用mapreduce時代的現有自定義輸入格式時,我遇到了Java泛型問題。Spark定製hadoop輸入格式java泛型錯誤

import com.google.protobuf.Message; 
import com.twitter.elephantbird.mapreduce.io.ProtobufWritable; 
public abstract class AbstractInputFormat<K extends Message, V> extends FileInputFormat<ProtobufWritable<K>, V> 

... 

import com.example.MyProto; // this extends Message 
public class MyInputFormat extends AbstractInputFormat<MyProto, Text> 

... 

SparkConf conf = new SparkConf().setAppName("Test"); 
SparkContext sc = new SparkContext(conf); 
JavaSparkContext jsc = JavaSparkContext.fromSparkContext(sc); 
JavaPairRDD myRdd = jsc.newAPIHadoopFile(logFile, MyInputFormat.class, ProtobufWritable.class, Text.class, 
        Job.getInstance().getConfiguration()); 

上述導致以下錯誤在myRdd

Bound mismatch: The generic method newAPIHadoopFile(String, Class<F>, Class<K>, Class<V>, Configuration) of type JavaSparkContext is not applicable for the arguments (String, Class<MyInputFormat>, Class<ProtobufWritable>, Class<Text>, Configuration). The inferred type MyInputFormat is not a valid substitute for the bounded parameter <F extends InputFormat<K,V>> 

不知道發生了什麼。在我看來,我滿足了界限?我無法發現問題?

This是被調用的scala代碼。

回答

0

以下更改爲我工作

public class MyInputFormat<K extends Message> extends AbstractInputFormat<MyProto, Text> 

public abstract class AbstractInputFormat<K extends Message, V> extends FileInputFormat<ProtobufWritable<K>, V>