use of org.apache.beam.runners.direct.StepTransformResult.Builder in project beam by apache.
the class ViewEvaluatorFactory method createEvaluator.
private <InT, OuT> TransformEvaluator<Iterable<InT>> createEvaluator(final AppliedPTransform<PCollection<Iterable<InT>>, PCollectionView<OuT>, WriteView<InT, OuT>> application) {
PCollection<Iterable<InT>> input = (PCollection<Iterable<InT>>) Iterables.getOnlyElement(application.getInputs().values());
final PCollectionViewWriter<InT, OuT> writer = context.createPCollectionViewWriter(input, (PCollectionView<OuT>) Iterables.getOnlyElement(application.getOutputs().values()));
return new TransformEvaluator<Iterable<InT>>() {
private final List<WindowedValue<InT>> elements = new ArrayList<>();
@Override
public void processElement(WindowedValue<Iterable<InT>> element) {
for (InT input : element.getValue()) {
elements.add(element.withValue(input));
}
}
@Override
public TransformResult<Iterable<InT>> finishBundle() {
writer.add(elements);
Builder resultBuilder = StepTransformResult.withoutHold(application);
if (!elements.isEmpty()) {
resultBuilder = resultBuilder.withAdditionalOutput(OutputType.PCOLLECTION_VIEW);
}
return resultBuilder.build();
}
};
}
Aggregations