下面是java代码。
JavaRDD<UserData> UserRowRDD = userSuccessRDD.mapPartitions(new FlatMapFunction<Iterator<String>, UserData>() {
@Override
public Iterator call(Iterator<String> input) throws Exception {
List<UserData> result = new ArrayList<>();
while (input.hasNext()) {
result.add(Util.getEnrichedUser(UserHeader, input.next()));
}
return result.iterator();
}
});
public static UserData getEnrichedUser(String[] header, String rddString) {
String[] parts = rddString.split("\\^");
UserData output = new UserData();
for (int i = 0; i < parts.length; i++) {
try {
BeanUtils.setProperty(output, header[i], parts[i]);
} catch (IllegalAccessException | InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return output;
}