Spark Dataset<Row> to ArrayList Java

Viewed 2082

I have a Dataset which holds values I want to output to a GUI. In the past I would use a

List<someObject>

I would like to maintain such a structure if possible, however not hardset on it if other solutions are available.

The columns of the Dataset row are

x:y:z:t

I tried creating a class with the schema of the output of Dataset subDf and then create a list

List<SinglePoint>aList=subDf.as(Encoders.bean(SinglePoint.class)).collectAsList();

But this crashes with a error hard to interpret

Exception in thread "main" java.lang.RuntimeException: Error while decoding: java.util.concurrent.ExecutionException: java.lang.Exception: failed to compile: org.codehaus.commons.compiler.CompileException: File 'generated.java', Line 27, Column 60: No applicable constructor/method found for zero actual parameters; candidates are: "database.util.SinglePoint(int, int, int, int)" /* 001 / public java.lang.Object generate(Object[] references) { / 002 */ return new SpecificSafeProjection(references);

I also tried

List<String>listTwo=subDf.map(row->row.mkString(),Encoders.STRING()).collectAsList()

But this did not have the desires structure to put into a GUI.

How can I convert a Dataset into an inter able list?

0 Answers
Related