我试图Dataset
在 Java 中创建一个,所以我编写了以下代码:
public Dataset createDataset(){
List<Person> list = new ArrayList<>();
list.add(new Person("name", 10, 10.0));
Dataset<Person> dateset = sqlContext.createDataset(list, Encoders.bean(Person.class));
return dataset;
}
Person
类是一个内部类。
然而,Spark 会抛出以下异常:
org.apache.spark.sql.AnalysisException: Unable to generate an encoder for inner class `....` without access to the scope that this class was defined in. Try moving this class out of its parent class.;
at org.apache.spark.sql.catalyst.encoders.ExpressionEncoder$$anonfun$2.applyOrElse(ExpressionEncoder.scala:264)
at org.apache.spark.sql.catalyst.encoders.ExpressionEncoder$$anonfun$2.applyOrElse(ExpressionEncoder.scala:260)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$3.apply(TreeNode.scala:243)
at org.apache.spark.sql.catalyst.trees.TreeNode$$anonfun$3.apply(TreeNode.scala:243)
at org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(TreeNode.scala:53)
at org.apache.spark.sql.catalyst.trees.TreeNode.transformDown(TreeNode.scala:242)
如何正确地做到这一点?