Mongodb Spark无法使用mongo hadoop连接器编译newAPIHadoopRDD';s BSONFileInputFormat

Mongodb Spark无法使用mongo hadoop连接器编译newAPIHadoopRDD';s BSONFileInputFormat,mongodb,scala,hadoop,apache-spark,Mongodb,Scala,Hadoop,Apache Spark,我在spark中使用mongo hadoop客户端(r1.5.2)从mongoDB和bson读取数据,如下链接:。到目前为止,我可以毫无问题地阅读mongoDB。但是,bson配置甚至无法编译。请帮忙 我在scala中的代码: dataConfig.set("mapred.input.dir", "path.bson") val documents = sc.newAPIHadoopRDD( dataConfig, classOf

我在spark中使用mongo hadoop客户端(r1.5.2)从mongoDB和bson读取数据,如下链接:。到目前为止,我可以毫无问题地阅读mongoDB。但是,bson配置甚至无法编译。请帮忙

我在scala中的代码:

dataConfig.set("mapred.input.dir", "path.bson")

    val documents = sc.newAPIHadoopRDD(
      dataConfig,                
      classOf[BSONFileInputFormat],  
      classOf[Object],            
      classOf[BSONObject])    
错误:

Error:(56, 24) inferred type arguments [Object,org.bson.BSONObject,com.mongodb.hadoop.mapred.BSONFileInputFormat] do not conform to method newAPIHadoopRDD's type parameter bounds [K,V,F <: org.apache.hadoop.mapreduce.InputFormat[K,V]]
    val documents = sc.newAPIHadoopRDD(
                       ^

错误:(56,24)推断的类型参数[Object,org.bson.BSONObject,com.mongodb.hadoop.mapred.BSONFileInputFormat]不符合方法newAPIHadoopRDD的类型参数边界[K,V,F我找到了它的解决方案!
这个问题似乎是由InputFormat的泛型引起的

newAPIHadoopRDD要求输入格式为

F <: org.apache.hadoop.mapreduce.InputFormat[K,V]

现在它可以正常工作:)

尝试使用BSONFileInputFormat而不是MongoInputFormat。另外,请指定您正在使用的mongo hadoop连接器的版本。
val documents = sc.newAPIHadoopRDD(
  dataConfig,                
  classOf[BSONFileInputFormat].asSubclass(classOf[org.apache.hadoop.mapreduce.lib.input.FileInputFormat[Object, BSONObject]]),  
  classOf[Object],            
  classOf[BSONObject])