试图强制扩展 W 的类以具有返回 WR 子类的数据集的方法 get。
abstract class WR
case class TGWR(
a: String,
b: String
) extends WR
abstract class W {
def get[T <: WR](): Dataset[T]
}
class TGW(sparkSession: SparkSession) extends W {
override def get[TGWR](): Dataset[TGWR] = {
import sparkSession.implicits._
Seq(TGWR("dd","dd").toDF().as[TGWR]
}
}
编译错误:
Unable to find encoder for type stored in a Dataset. Primitive types (Int, String, etc) and Product types (case classes) are supported by importing spark.implicits._ Support for serializing other types will be added in future releases.
如果我将 get 函数更改为以下内容:
def get(): Dataset[TGWR]
和
override def get(): Dataset[TGWR] = {...
它可以编译 - 因此我怀疑由于继承/类型层次结构存在问题。