Search in sources :

Example 1 with Builder

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();
        }
    };
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) WindowedValue(org.apache.beam.sdk.util.WindowedValue) Builder(org.apache.beam.runners.direct.StepTransformResult.Builder) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Builder (org.apache.beam.runners.direct.StepTransformResult.Builder)1 WindowedValue (org.apache.beam.sdk.util.WindowedValue)1 PCollection (org.apache.beam.sdk.values.PCollection)1