Scala 使用递归case类的Spark
我有一个递归的数据结构。Spark给出了以下错误:Scala 使用递归case类的Spark,scala,apache-spark,apache-spark-sql,apache-spark-dataset,Scala,Apache Spark,Apache Spark Sql,Apache Spark Dataset,我有一个递归的数据结构。Spark给出了以下错误: Exception in thread "main" java.lang.UnsupportedOperationException: cannot have circular references in class, but got the circular reference of class BulletPoint 例如,我编写了以下代码: case class BulletPoint(item: String, children: L
Exception in thread "main" java.lang.UnsupportedOperationException: cannot have circular references in class, but got the circular reference of class BulletPoint
例如,我编写了以下代码:
case class BulletPoint(item: String, children: List[BulletPoint])
object TestApp extends App {
val sparkSession = SparkSession
.builder()
.appName("spark app")
.master(s"local")
.getOrCreate()
import sparkSession.implicits._
sparkSession.createDataset(List(BulletPoint("1", Nil), BulletPoint("2", Nil)))
}
有人知道如何解决这个问题吗?例外情况相当明确-默认情况下不支持这种情况。您必须记住,
数据集
被编码到关系模式中,因此所有必需的字段都必须预先声明并绑定。这里没有递归结构的位置
这里有一扇小窗户-:
或同等产品:
implicit val bulletPointEncoder = Encoders.kryo[BulletPoint]
sparkSession.createDataset(List(
BulletPoint("1", Nil), BulletPoint("2", Nil)
))
但是,除非有严格的必要,否则这并不是您希望在代码中包含的内容。在我看来,这似乎是唯一的解决方案,我试图看看是否还有其他解决方案。非常感谢你的支持。
implicit val bulletPointEncoder = Encoders.kryo[BulletPoint]
sparkSession.createDataset(List(
BulletPoint("1", Nil), BulletPoint("2", Nil)
))