use of org.talend.sdk.component.runtime.beam.transform.ViewsMappingTransform in project component-runtime by Talend.
the class Main method main.
public static void main(final String[] args) throws IOException {
final Config options = PipelineOptionsFactory.fromArgs(args).as(Config.class);
final Pipeline pipeline = Pipeline.create(options);
try (final FileWriter writer = new FileWriter(options.getInputFile())) {
writer.write("normal;6\nmarilyn;36");
}
final ComponentManager manager = ComponentManager.instance();
pipeline.apply(TalendIO.read(manager.findMapper("sample", "reader", 1, new HashMap<String, String>() {
{
// will be migrated to "file" with the migration handler
put("old_file", options.getInputFile());
}
}).orElseThrow(() -> new IllegalArgumentException("No reader sample#reader, existing: " + manager.availablePlugins())))).apply(new ViewsMappingTransform(emptyMap(), "sample")).apply(TalendFn.asFn(manager.findProcessor("sample", "mapper", 1, emptyMap()).orElseThrow(() -> new IllegalStateException("didn't find the processor")))).apply(ParDo.of(new ToStringFn())).apply(TextIO.write().to(ValueProvider.StaticValueProvider.of(options.getOutputFile())));
final PipelineResult.State state = pipeline.run().waitUntilFinish();
System.out.println(state);
}
use of org.talend.sdk.component.runtime.beam.transform.ViewsMappingTransform 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());
}
Aggregations