I have a Dataset df, read using spark.read().json
It's schema is something like the following:
root
|-- items: struct (nullable = true)
| |-- item: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- batch-id column: long (nullable = true)
| | | |-- id: string (nullable = true)
| | | |-- name: string (nullable = true)
| | | |-- type: string (nullable = true)
I want use a FlatMapFunction to get a dataset with the inner schema(id,name,type).
I want to do something like the following:
df.flatMap(mapperFunction(),RowEncoder.apply(someSchema);
public static FlatMapFunction<Row,Row> mapperFunction() {
return row -> {
Row r1 = row.getAs("items");
List<Row> r2 = r1.getList(0); //This will explode the column
StructType schema = r2.get(0).schema();
//I know list doesn't have map function, I want to know what can be done here
return r2.flatMap(mapperFunction(),RowEncoder.apply(schema);
};
}