I can't figure out a way to convert a List of Test objects to a Dataset in Spark This is my class:
public class Test {
public String a;
public String b;
public Test(String a, String b){
this.a = a;
this.b = b;
}
public List getList(){
List l = new ArrayList();
l.add(this.a);
l.add(this.b);
return l;
}
}
Your code in the comments to create a DataFrame is correct. However, there is a problem with the way you define Test
. You can create DataFrames using your code only from Java Beans. Your Test
class is not a Java Bean. Once you fix that, you can use the following code to create a DataFrame:
Dataset<Row> dataFrame = spark.createDataFrame(listOfTestClasses, Test.class);
and these lines to create a typed Dataset:
Encoder<Test> encoder = Encoders.bean(Test.class);
Dataset<Test> dataset = spark.createDataset(listOfTestClasses, encoder);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With