Я хочу преобразовать небольшой Pcollection в список и построить HashMap. Мне удалось объединить элементы Pcollection во всем мире в итерабируемое, но итерабильный находится внутри Pcollection. Как извлечь итерабильный (который теперь содержит все мои данные) из PCOLLECTION.public static class Record {
String label;
Float score;
}
< /code>
Вот мой метод Gethmap. < /p>
public static HashMap getHMap(Pipeline pipeline, String scoreFile) {
HashMap hmap = new HashMap();
List recordsList = new ArrayList();
PCollection coll = read(pipeline, scoreFile);
PCollection recordsListPColl = coll.apply("GetInterable", Combine.globally(new ToList()));
//To-Do: extract the Iterable from the PCollection and move it to recordsList
for (Record rec : recordsList) {
hmap.put(rec.label, rec.score);
}
return hmap;
}
< /code>
Для дополнительной ссылки, вот моя функция Colist Combine < /p>
public class ToList extends Combine.CombineFn {
@Override
public List createAccumulator() {
return new ArrayList();
}
@Override
public List addInput(List accumulator, T input) {
accumulator.add(input);
return accumulator;
}
@Override
public List mergeAccumulators(Iterable accumulators) {
Iterator iter = accumulators.iterator();
if (!iter.hasNext()) {
return createAccumulator();
}
List res = iter.next();
while (iter.hasNext()) {
res.addAll(iter.next());
}
return res;
}
@Override
public Iterable extractOutput(List accumulator) {
return accumulator;
}
}
Подробнее здесь: https://stackoverflow.com/questions/757 ... e-globally