我正在尝试编写一个应该将其输出放入HBase的Spark作业.据我所知,这样做的正确方法是使用方法saveAsHadoopDataset
上org.apache.spark.rdd.PairRDDFunctions
-这需要我的RDD
是由对.
该方法saveAsHadoopDataset
需要一个JobConf
,这就是我想要构建的.根据这个链接,我必须设置的一件事JobConf
是输出格式(实际上它没有用),比如
jobConfig.setOutputFormat(classOf[TableOutputFormat])
问题是显然这不会编译,因为它TableOutputFormat
是通用的,即使它忽略了它的类型参数.所以我尝试了各种组合,比如
jobConfig.setOutputFormat(classOf[TableOutputFormat[Unit]]) jobConfig.setOutputFormat(classOf[TableOutputFormat[_]])
但无论如何我都会收到错误
required: Class[_ <: org.apache.hadoop.mapred.OutputFormat[_, _]]
现在,据我所知,Class[_ <: org.apache.hadoop.mapred.OutputFormat[_, _]]
转换为Class[T] forSome { type T <: org.apache.hadoop.mapred.OutputFormat[_, _] }
.这是我认为我有问题的地方,因为:
Class
是不变的
TableOutputFormat[T] <: OutputFormat[T, Mutation]
但是
我不确定存在类型如何与需求中的子类型交互 T <: OutputFormat[_, _]
有没有办法获得的一个亚型OutputFormat[_, _]
的TableOutputFormat
?似乎问题源于Java和Scala中的泛型之间的差异 - 我能为此做些什么?
编辑:
事实证明这甚至更微妙.我试图在REPL中定义自己的方法
def foo(x: Class[_ <: OutputFormat[_, _]]) = x
我实际上可以调用它
foo(classOf[TableOutputFormat[Unit]])
甚至
foo(classOf[TableOutputFormat[_]])
对那个问题.但我不能打电话
jobConf.setOutputFormat(classOf[TableOutputFormat[_]])
setOutputFormat
Java中的原始签名是void setOutputFormat(Class extends OutputFormat> theClass)
.我如何从Scala中调用它?