I am converting spark dataset into list of hash maps by using below approach
List<HashMap> finalJsonMap = new ArrayList<HashMap>();
srcData.foreachPartition(new ForeachPartitionFunction<Row>() {
public void call(Iterator<Row> t) throws Exception {
while (t.hasNext()){
Row eachRow = t.next();
HashMap rowMap = new HashMap();
for(int j=0;j<grpdColNames.size();j++){
rowMap.put(grpdColNames.get(j), eachRow.getString(j));
}
finalJsonMap.add(rowMap);
}
}
});
The iteration is working fine but I am unable to add rowMap into finalJsonMap.
What is the best approach to do this?