use of org.talend.dataprep.transformation.pipeline.model.DiffWriterNode in project data-prep by Talend.
the class PipelineDiffTransformer method buildExecutable.
/**
* Starts the transformation in preview mode.
*
* @param input the dataset content.
* @param configuration The {@link Configuration configuration} for this transformation.
*/
@Override
public ExecutableTransformer buildExecutable(DataSet input, Configuration configuration) {
Validate.notNull(input, "Input cannot be null.");
final PreviewConfiguration previewConfiguration = (PreviewConfiguration) configuration;
final RowMetadata rowMetadata = input.getMetadata().getRowMetadata();
final TransformerWriter writer = writerRegistrationService.getWriter(configuration.formatId(), configuration.output(), configuration.getArguments());
// Build diff pipeline
final Node diffWriterNode = new DiffWriterNode(writer);
final String referenceActions = previewConfiguration.getReferenceActions();
final String previewActions = previewConfiguration.getPreviewActions();
final Pipeline referencePipeline = buildPipeline(rowMetadata, referenceActions);
final Pipeline previewPipeline = buildPipeline(rowMetadata, previewActions);
// Filter source records (extract TDP ids information)
final List<Long> indexes = previewConfiguration.getIndexes();
final boolean isIndexLimited = indexes != null && !indexes.isEmpty();
final Long minIndex = isIndexLimited ? indexes.stream().mapToLong(Long::longValue).min().getAsLong() : 0L;
final Long maxIndex = isIndexLimited ? indexes.stream().mapToLong(Long::longValue).max().getAsLong() : Long.MAX_VALUE;
final Predicate<DataSetRow> filter = isWithinWantedIndexes(minIndex, maxIndex);
// Build diff pipeline
final Node diffPipeline = //
NodeBuilder.filteredSource(filter).dispatchTo(referencePipeline, //
previewPipeline).zipTo(//
diffWriterNode).build();
// wrap this transformer into an ExecutableTransformer
return new ExecutableTransformer() {
@Override
public void execute() {
// Run diff
try {
// Print pipeline before execution (for debug purposes).
diffPipeline.logStatus(LOGGER, "Before execution: {}");
input.getRecords().forEach(r -> diffPipeline.exec().receive(r, rowMetadata));
diffPipeline.exec().signal(Signal.END_OF_STREAM);
} finally {
// Print pipeline after execution (for debug purposes).
diffPipeline.logStatus(LOGGER, "After execution: {}");
}
}
@Override
public void signal(Signal signal) {
diffPipeline.exec().signal(signal);
}
};
}
Aggregations