use of org.talend.sdk.component.runtime.output.OutputFactory in project component-runtime by Talend.
the class BeamProcessorChainImpl method onNext.
@Override
public void onNext(final InputFactory input, final OutputFactory output) {
Collection<InputFactory> finalInput = singletonList(input);
if (!preProcessors.isEmpty()) {
for (final Processor p : preProcessors) {
final StoringOuputFactory tmpOutput = new StoringOuputFactory();
finalInput.forEach(in -> p.onNext(in, tmpOutput));
if (tmpOutput.getValues() == null) {
// chain is stopped
return;
}
finalInput = tmpOutput.getValues().stream().map(val -> (InputFactory) name -> {
if (!Branches.DEFAULT_BRANCH.equals(name)) {
throw new IllegalArgumentException("Only default branch is supported at the moment");
}
return val;
}).collect(toList());
}
}
finalInput.forEach(in -> lastProcessor.onNext(in, output));
}
use of org.talend.sdk.component.runtime.output.OutputFactory in project component-runtime by Talend.
the class TalendIOTest method processorMulti.
@Test
public void processorMulti() {
final PCollection<SampleLength> out = pipeline.apply(Create.of(new Sample("a"), new Sample("bb")).withCoder(JsonbCoder.of(Sample.class, PLUGIN))).apply(UUID.randomUUID().toString(), ParDo.of(new DoFn<Sample, JsonObject>() {
@ProcessElement
public void toData(final ProcessContext sample) {
sample.output(JSONB.fromJson(JSONB.toJson(sample.element()), JsonObject.class));
}
})).setCoder(JsonpJsonObjectCoder.of(PLUGIN)).apply(new ViewsMappingTransform(emptyMap(), PLUGIN)).apply(TalendFn.asFn(new BaseTestProcessor() {
@Override
public void onNext(final InputFactory input, final OutputFactory factory) {
factory.create(Branches.DEFAULT_BRANCH).emit(new SampleLength(JSONB.fromJson(input.read(Branches.DEFAULT_BRANCH).toString(), Sample.class).data.length()));
}
})).apply(ParDo.of(new DoFn<JsonObject, SampleLength>() {
@ProcessElement
public void onElement(final ProcessContext ctx) {
ctx.output(JSONB.fromJson(ctx.element().getJsonArray("__default__").getJsonObject(0).toString(), SampleLength.class));
}
}));
PAssert.that(out.apply(UUID.randomUUID().toString(), ParDo.of(new DoFn<SampleLength, Integer>() {
@ProcessElement
public void toInt(final ProcessContext pc) {
pc.output(pc.element().len);
}
}))).containsInAnyOrder(1, 2);
assertEquals(PipelineResult.State.DONE, pipeline.run().getState());
}
use of org.talend.sdk.component.runtime.output.OutputFactory in project component-runtime by Talend.
the class DIBatchSimulationTest method doDi.
private void doDi(final ComponentManager manager, final Collection<Object> sourceData, final Collection<Object> processorData, final Optional<Processor> proc, final Optional<Mapper> mapper) {
final Map<String, Object> globalMap = new HashMap<>();
try {
final Processor processor = proc.orElseThrow(() -> new IllegalStateException("scanning failed"));
JobStateAware.init(processor, globalMap);
final Jsonb jsonbProcessor = Jsonb.class.cast(manager.findPlugin(processor.plugin()).get().get(ComponentManager.AllServices.class).getServices().get(Jsonb.class));
final AutoChunkProcessor processorProcessor = new AutoChunkProcessor(100, processor);
processorProcessor.start();
globalMap.put("processorProcessor", processorProcessor);
final InputsHandler inputsHandlerProcessor = new InputsHandler(jsonbProcessor);
inputsHandlerProcessor.addConnection("FLOW", row1Struct.class);
final OutputsHandler outputHandlerProcessor = new OutputsHandler(jsonbProcessor);
final InputFactory inputsProcessor = inputsHandlerProcessor.asInputFactory();
final OutputFactory outputsProcessor = outputHandlerProcessor.asOutputFactory();
final Mapper tempMapperMapper = mapper.orElseThrow(() -> new IllegalStateException("scanning failed"));
JobStateAware.init(tempMapperMapper, globalMap);
doRun(manager, sourceData, processorData, globalMap, processorProcessor, inputsHandlerProcessor, outputHandlerProcessor, inputsProcessor, outputsProcessor, tempMapperMapper);
} finally {
doClose(globalMap);
}
}
Aggregations