Search in sources :

Example 1 with MixedContentMap

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

the class PreparationAPITest method testPreparationPreviewOnPreparationWithTrimAction_TDP_5057.

/**
 * Verify a calculate time since preview after a trim step on a preparation
 * see <a href="https://jira.talendforge.org/browse/TDP-5057">TDP-5057</a>
 */
@Test
public void testPreparationPreviewOnPreparationWithTrimAction_TDP_5057() throws IOException {
    // Create a dataset from csv
    final String datasetId = testClient.createDataset("preview/best_sad_songs_of_all_time.csv", "testPreview");
    // Create a preparation
    String preparationId = testClient.createPreparationFromDataset(datasetId, "testPrep", home.getId());
    // apply trim action on the 8nd column to make this column date valid
    Map<String, String> trimParameters = new HashMap<>();
    trimParameters.put("create_new_column", "false");
    trimParameters.put("padding_character", "whitespace");
    trimParameters.put("scope", "column");
    trimParameters.put("column_id", "0008");
    trimParameters.put("column_name", "Added At");
    trimParameters.put("row_id", "null");
    testClient.applyAction(preparationId, Trim.TRIM_ACTION_NAME, trimParameters);
    // check column is date valid after trim action
    InputStream inputStream = testClient.getPreparation(preparationId).asInputStream();
    mapper.getDeserializationConfig().without(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
    RowMetadata preparationContent = mapper.readValue(inputStream, Data.class).metadata;
    List<PatternFrequency> patternFrequencies = preparationContent.getColumns().get(8).getStatistics().getPatternFrequencies();
    assertTrue(patternFrequencies.stream().map(// 
    PatternFrequency::getPattern).anyMatch("yyyy-MM-dd"::equals));
    // create a preview of calculate time since action
    PreviewAddParameters previewAddParameters = new PreviewAddParameters();
    previewAddParameters.setDatasetId(datasetId);
    previewAddParameters.setPreparationId(preparationId);
    previewAddParameters.setTdpIds(Arrays.asList(1, 2, 3, 4, 5, 6, 7));
    Action calculateTimeUntilAction = new Action();
    calculateTimeUntilAction.setName(ComputeTimeSince.TIME_SINCE_ACTION_NAME);
    MixedContentMap actionParameters = new MixedContentMap();
    actionParameters.put("create_new_column", "true");
    actionParameters.put("time_unit", "HOURS");
    actionParameters.put("since_when", "now_server_side");
    actionParameters.put("scope", "column");
    actionParameters.put("column_id", "0008");
    actionParameters.put("column_name", "Added At");
    calculateTimeUntilAction.setParameters(actionParameters);
    previewAddParameters.setActions(Collections.singletonList(calculateTimeUntilAction));
    JsonPath jsonPath = given().contentType(// 
    ContentType.JSON).body(// 
    previewAddParameters).expect().statusCode(200).log().ifError().when().post(// 
    "/api/preparations/preview/add").jsonPath();
    // check non empty value for the new column
    assertEquals(// 
    "new preview column should contains values according to calculate time since action", // 
    0, jsonPath.getList("records.0009").stream().map(String::valueOf).filter(StringUtils::isBlank).count());
}
Also used : Action(org.talend.dataprep.api.preparation.Action) EntityBuilder.buildAction(org.talend.dataprep.api.service.EntityBuilder.buildAction) HashMap(java.util.HashMap) InputStream(java.io.InputStream) JsonPath(com.jayway.restassured.path.json.JsonPath) PreviewAddParameters(org.talend.dataprep.api.service.api.PreviewAddParameters) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) StringUtils(org.apache.commons.lang.StringUtils) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap) Test(org.junit.Test)

Example 2 with MixedContentMap

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

the class EntityBuilder method params.

public static MixedContentMap params(String... params) {
    MixedContentMap secondActionParams = new MixedContentMap();
    if (params.length > 0) {
        for (int i = 1; i < params.length; i += 2) {
            String param = params[i - 1];
            String value = params[i];
            secondActionParams.put(param, value);
        }
    }
    return secondActionParams;
}
Also used : MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap)

Example 3 with MixedContentMap

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

the class ReorderStepsUtilsTest method createAppendStep.

private static AppendStep createAppendStep(String usedColumnId, List<String> createdColumns) {
    AppendStep firstStep = new AppendStep();
    StepDiff firstStepDiff = new StepDiff();
    firstStepDiff.setCreatedColumns(createdColumns);
    firstStep.setDiff(firstStepDiff);
    Action firstStepAction = new Action();
    MixedContentMap parameters = new MixedContentMap();
    parameters.put(ImplicitParameters.COLUMN_ID.getKey(), usedColumnId);
    firstStepAction.setParameters(parameters);
    firstStep.setActions(asList(firstStepAction));
    return firstStep;
}
Also used : Action(org.talend.dataprep.api.preparation.Action) StepDiff(org.talend.dataprep.api.preparation.StepDiff) MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap) AppendStep(org.talend.dataprep.api.preparation.AppendStep)

Example 4 with MixedContentMap

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

the class EntityBuilder method buildParametersMap.

public static MixedContentMap buildParametersMap(String... params) {
    MixedContentMap secondActionParams = new MixedContentMap();
    if (params.length > 0) {
        for (int i = 1; i < params.length; i += 2) {
            String param = params[i - 1];
            String value = params[i];
            secondActionParams.put(param, value);
        }
    }
    return secondActionParams;
}
Also used : MixedContentMap(org.talend.dataprep.api.preparation.MixedContentMap)

Aggregations

MixedContentMap (org.talend.dataprep.api.preparation.MixedContentMap)4 Action (org.talend.dataprep.api.preparation.Action)2 JsonPath (com.jayway.restassured.path.json.JsonPath)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 StringUtils (org.apache.commons.lang.StringUtils)1 Test (org.junit.Test)1 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)1 PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)1 AppendStep (org.talend.dataprep.api.preparation.AppendStep)1 StepDiff (org.talend.dataprep.api.preparation.StepDiff)1 EntityBuilder.buildAction (org.talend.dataprep.api.service.EntityBuilder.buildAction)1 PreviewAddParameters (org.talend.dataprep.api.service.api.PreviewAddParameters)1