を存在しない限り、私はカスタムの入力とXMLIO.scala
でオーバー出力フォーマットを定義した[CustomInputFormat] classOf:私が使用しようとしているスカラ/ Hadoopの:コンパイラエラー時に使用してCustomInputFormatのインスタンスが
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] { /*...*/ }
}
仕事は私がExample.scala
にオーバー定義しています:
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] ^
XMLInputFormat
はFileInputFormat
のサブクラスであり、InputFormat
のサブクラスであることを考えると、私にとっては奇妙に思えるものです。
REPLでちょっと遊んで、私は奇妙な回避策を見つけました。入力形式クラスを設定する前にXMLInputFormat
のインスタンスを作成すると、コンパイルエラーは発生しません。つまり、次のようにコンパイルできます。
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 x = new XMLInputFormat()
val job = new Job(new Configuration(), "")
job setInputFormatClass classOf[XMLInputFormat]
}
}
ここでは何が起こっていますか?これほど多くのハックのように見えない修正がありますか?