Search in sources :

Example 1 with PreviewConfiguration

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);
        }
    };
}
Also used : DiffWriterNode(org.talend.dataprep.transformation.pipeline.model.DiffWriterNode) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) Node(org.talend.dataprep.transformation.pipeline.Node) DiffWriterNode(org.talend.dataprep.transformation.pipeline.model.DiffWriterNode) Pipeline(org.talend.dataprep.transformation.pipeline.Pipeline) Signal(org.talend.dataprep.transformation.pipeline.Signal) PreviewConfiguration(org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration) ExecutableTransformer(org.talend.dataprep.transformation.api.transformer.ExecutableTransformer) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) TransformerWriter(org.talend.dataprep.transformation.api.transformer.TransformerWriter) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow)

Example 2 with PreviewConfiguration

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();
}
Also used : PreviewConfiguration(org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration)

Aggregations

PreviewConfiguration (org.talend.dataprep.transformation.api.transformer.configuration.PreviewConfiguration)2 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)1 ExecutableTransformer (org.talend.dataprep.transformation.api.transformer.ExecutableTransformer)1 TransformerWriter (org.talend.dataprep.transformation.api.transformer.TransformerWriter)1 Node (org.talend.dataprep.transformation.pipeline.Node)1 Pipeline (org.talend.dataprep.transformation.pipeline.Pipeline)1 Signal (org.talend.dataprep.transformation.pipeline.Signal)1 DiffWriterNode (org.talend.dataprep.transformation.pipeline.model.DiffWriterNode)1 BasicNode (org.talend.dataprep.transformation.pipeline.node.BasicNode)1