Scala/Hadoop:除非存在CustomInputFormat实例,否则使用[CustomInputFormat]类时出现编译器错误
我在Scala/Hadoop:除非存在CustomInputFormat实例,否则使用[CustomInputFormat]类时出现编译器错误,scala,hadoop,Scala,Hadoop,我在XMLIO.scala中定义了自定义输入和输出格式: import scala.xml.Node import org.apache.hadoop.lib.input.FileInputFormat import org.apache.hadoop.lib.output.FileOutputFormat import org.apache.hadoop.mapreduce.{ RecordReader, RecordWriter } // ... object XMLIO { cla
XMLIO.scala
中定义了自定义输入和输出格式:
import scala.xml.Node
import org.apache.hadoop.lib.input.FileInputFormat
import org.apache.hadoop.lib.output.FileOutputFormat
import org.apache.hadoop.mapreduce.{ RecordReader, RecordWriter }
// ...
object XMLIO {
class XMLInputFormat extends FileInputFormat[LongWritable, Node] { /*...*/ }
class XMLRecordReader extends RecordReader[LongWritable, Node] { /*...*/ }
class XMLOutputFormat extends FileOutputFormat[LongWritable, Node] { /*...*/ }
class XMLRecordWriter extends RecordWriter[LongWritable, Node] { /*...*/ }
}
import XMLIO._
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.mapreduce.Job
object Example {
@throws(classOf[Exception])
def main( args : Array[String] ) {
val job = new Job(new Configuration(), "")
job setInputFormatClass classOf[XMLInputFormat]
}
}
我试图将其用于我在示例中定义的作业。scala
:
import scala.xml.Node
import org.apache.hadoop.lib.input.FileInputFormat
import org.apache.hadoop.lib.output.FileOutputFormat
import org.apache.hadoop.mapreduce.{ RecordReader, RecordWriter }
// ...
object XMLIO {
class XMLInputFormat extends FileInputFormat[LongWritable, Node] { /*...*/ }
class XMLRecordReader extends RecordReader[LongWritable, Node] { /*...*/ }
class XMLOutputFormat extends FileOutputFormat[LongWritable, Node] { /*...*/ }
class XMLRecordWriter extends RecordWriter[LongWritable, Node] { /*...*/ }
}
import XMLIO._
import org.apache.hadoop.conf.Configuration
import org.apache.hadoop.mapreduce.Job
object Example {
@throws(classOf[Exception])
def main( args : Array[String] ) {
val job = new Job(new Configuration(), "")
job setInputFormatClass classOf[XMLInputFormat]
}
}
但是,这给了我一个编译器错误:
[ERROR] /path/to/Example.scala:8: error: type mismatch;
[INFO] found : java.lang.Class[XMLInputFormat](classOf[XMLInputFormat])
[INFO] required: java.lang.Class[_ <: org.apache.hadoop.mapreduce.InputFormat]
[INFO] job setInputFormatClass classOf[XMLInputFormat]
[INFO] ^
这是怎么回事?有没有一个修复程序看起来不像是一个黑客?看起来这是scala 2.9.0的一个bug(我正在使用它)。当我升级到scala 2.9.1时,问题就消失了