Search in sources :

Example 6 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class TransformationService method getCreatedColumns.

/**
 * Compare the results of 2 sets of actions, and return the diff metadata Ex : the created columns ids
 */
private StepDiff getCreatedColumns(final PreviewParameters previewParameters) {
    final DataSetGetMetadata dataSetGetMetadata = context.getBean(DataSetGetMetadata.class, previewParameters.getDataSetId());
    DataSetMetadata dataSetMetadata = dataSetGetMetadata.execute();
    StepDiff stepDiff;
    if (dataSetGetMetadata.isSuccessfulExecution() && dataSetMetadata != null) {
        RowMetadata metadataBase = dataSetMetadata.getRowMetadata();
        RowMetadata metadataAfter = metadataBase.clone();
        applyActionsOnMetadata(metadataBase, previewParameters.getBaseActions());
        applyActionsOnMetadata(metadataAfter, previewParameters.getNewActions());
        metadataAfter.diff(metadataBase);
        List<String> createdColumnIds = metadataAfter.getColumns().stream().filter(c -> Flag.NEW.getValue().equals(c.getDiffFlagValue())).map(ColumnMetadata::getId).collect(Collectors.toList());
        stepDiff = new StepDiff();
        stepDiff.setCreatedColumns(createdColumnIds);
    } else {
        stepDiff = null;
    // maybe throw an exception...
    }
    return stepDiff;
}
Also used : StepDiff(org.talend.dataprep.api.preparation.StepDiff) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetGetMetadata(org.talend.dataprep.command.dataset.DataSetGetMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata)

Example 7 with StepDiff

use of org.talend.dataprep.api.preparation.StepDiff in project data-prep by Talend.

the class EntityBuilder method diff.

public static StepDiff diff(String... createdColumns) {
    StepDiff stepDiff = new StepDiff();
    stepDiff.setCreatedColumns(Arrays.asList(createdColumns));
    return stepDiff;
}
Also used : StepDiff(org.talend.dataprep.api.preparation.StepDiff)

Aggregations

StepDiff (org.talend.dataprep.api.preparation.StepDiff)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)4 Test (org.junit.Test)2 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HttpPut (org.apache.http.client.methods.HttpPut)1 InputStreamEntity (org.apache.http.entity.InputStreamEntity)1 BasicHeader (org.apache.http.message.BasicHeader)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 Action (org.talend.dataprep.api.preparation.Action)1 AppendStep (org.talend.dataprep.api.preparation.AppendStep)1 MixedContentMap (org.talend.dataprep.api.preparation.MixedContentMap)1 DataSetGetMetadata (org.talend.dataprep.command.dataset.DataSetGetMetadata)1 TDPException (org.talend.dataprep.exception.TDPException)1