use of org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration 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);
}
};
}
use of org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration in project data-prep by Talend.
the class TransformationService method executePreview.
/**
* Execute the preview and write result in the provided output stream
*
* @param actions The actions to execute to diff with reference
* @param referenceActions The reference actions
* @param indexes The record indexes to diff. If null, it will process all records
* @param dataSet The dataset (column metadata and records)
* @param output The output stream where to write the result
*/
private void executePreview(final String actions, final String referenceActions, final String indexes, final DataSet dataSet, final OutputStream output) {
final PreviewConfiguration configuration = //
PreviewConfiguration.preview().withActions(//
actions).withIndexes(//
indexes).fromReference(//
Configuration.builder().format(//
JSON).output(//
output).actions(//
referenceActions).build()).build();
factory.get(configuration).buildExecutable(dataSet, configuration).execute();
}
Aggregations