当我写一个特质时喜欢这个:
trait Extractor[T] {
def parse(sc: SparkContext, path: String): RDD[T]
def extract(sc: SparkContext, path: String, output: String): Unit = {
val rdd = parse(sc, path)
val sqlContext = new HiveContext(sc)
import sqlContext.implicits._
SaveUtil.saveAsOrc(rdd.toDF(), output) // error
}
}
我想将通用T
指定给案例类:
case class X(uid: String, app: String, tag: String)
case class Y(uid: String, dvc: String, tag: String)
我是斯卡拉的新手。隐式转换和协变似乎不起作用。怎么样?
答案 0 :(得分:0)
object ExtractorX extends Extractor[X] {
override parse(sc: SparkContext, path: String): RDD[X] = ...
}
或
val extractorX = new Extractor[X] {
override parse(sc: SparkContext, path: String): RDD[X] = ...
}