Search in sources :

Example 51 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class ClearMatchingTest method should_clear_because_pattern_match.

@Test
public void should_clear_because_pattern_match() throws Exception {
    // given
    final Map<String, String> firstRowValues = new HashMap<>();
    firstRowValues.put("0000", "David Bowie");
    firstRowValues.put("0001", "N");
    firstRowValues.put("0002", "Something");
    final Map<String, String> secondRowValues = new HashMap<>();
    secondRowValues.put("0000", "Beer");
    secondRowValues.put("0001", "T");
    secondRowValues.put("0002", "NotSomething");
    final Map<String, String> thirdRowValues = new HashMap<>();
    thirdRowValues.put("0000", "Wine");
    thirdRowValues.put("0001", "True");
    thirdRowValues.put("0002", "Somethin");
    List<DataSetRow> rows = // 
    Arrays.asList(// 
    new DataSetRow(firstRowValues), // 
    new DataSetRow(secondRowValues), new DataSetRow(thirdRowValues));
    for (DataSetRow row : rows) {
        final RowMetadata rowMetadata = row.getRowMetadata();
        rowMetadata.getById("0002").setType(Type.STRING.getName());
    }
    parameters.put(ClearMatching.VALUE_PARAMETER, generateJson(".*Something", ReplaceOnValueHelper.REGEX_MODE));
    // when
    ActionTestWorkbench.test(rows, actionRegistry, factory.create(action, parameters));
    // then
    // 
    Assertions.assertThat(rows.get(0).values()).isNotEmpty().hasSize(// 
    3).containsExactly(// 
    MapEntry.entry("0000", "David Bowie"), // 
    MapEntry.entry("0001", "N"), MapEntry.entry("0002", ""));
    // 
    Assertions.assertThat(rows.get(1).values()).isNotEmpty().hasSize(// 
    3).containsExactly(// 
    MapEntry.entry("0000", "Beer"), // 
    MapEntry.entry("0001", "T"), MapEntry.entry("0002", ""));
    // 
    Assertions.assertThat(rows.get(2).values()).isNotEmpty().hasSize(// 
    3).containsExactly(// 
    MapEntry.entry("0000", "Wine"), // 
    MapEntry.entry("0001", "True"), MapEntry.entry("0002", "Somethin"));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 52 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class CopyColumnTest method should_update_metadata.

@Test
public void should_update_metadata() {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(createMetadata("0000", "recipe"));
    input.add(createMetadata("0001", "steps"));
    input.add(createMetadata("0002", "last_update"));
    final RowMetadata rowMetadata = new RowMetadata(input);
    final List<ColumnMetadata> expectedColumns = new ArrayList<>();
    expectedColumns.add(createMetadata("0000", "recipe"));
    expectedColumns.add(createMetadata("0001", "steps"));
    expectedColumns.add(createMetadata("0003", "steps_copy"));
    expectedColumns.add(createMetadata("0002", "last_update"));
    final RowMetadata expected = new RowMetadata(expectedColumns);
    // when
    final DataSetRow row = new DataSetRow(rowMetadata);
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expected, row.getRowMetadata());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 53 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class CopyColumnTest method test_TDP_1184.

/**
 * Test with non-consecutive columns ids. This can occurs after some column deletion.
 */
@Test
public void test_TDP_1184() {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(columnBaseBuilder().name("recipe").type(Type.STRING).build());
    input.add(columnBaseBuilder().name("steps").type(Type.STRING).build());
    input.add(columnBaseBuilder().name("last update").type(Type.STRING).build());
    input.add(columnBaseBuilder().name("column to delete").type(Type.STRING).build());
    final RowMetadata rowMetadata = new RowMetadata(input);
    // when
    rowMetadata.deleteColumnById("0003");
    final DataSetRow row = new DataSetRow(rowMetadata);
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final List<ColumnMetadata> actual = row.getRowMetadata().getColumns();
    assertEquals(actual.size(), 4);
    final ColumnMetadata copiedColumn = row.getRowMetadata().getById("0004");
    assertNotNull(copiedColumn);
    assertEquals("steps_copy", copiedColumn.getName());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 54 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class ExtractEmailDomain method compile.

@Override
public void compile(ActionContext context) {
    super.compile(context);
    if (ActionsUtils.doesCreateNewColumn(context.getParameters(), true)) {
        final List<ActionsUtils.AdditionalColumn> additionalColumns = new ArrayList<>();
        final RowMetadata rowMetadata = context.getRowMetadata();
        final ColumnMetadata column = rowMetadata.getById(context.getColumnId());
        additionalColumns.add(ActionsUtils.additionalColumn().withKey(LOCAL).withName(column.getName() + LOCAL));
        additionalColumns.add(ActionsUtils.additionalColumn().withKey(DOMAIN).withName(column.getName() + DOMAIN));
        ActionsUtils.createNewColumn(context, additionalColumns);
    }
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Example 55 with RowMetadata

use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.

the class Contains method getAdditionalColumns.

protected List<ActionsUtils.AdditionalColumn> getAdditionalColumns(ActionContext context) {
    final List<ActionsUtils.AdditionalColumn> additionalColumns = new ArrayList<>();
    final Map<String, String> parameters = context.getParameters();
    final RowMetadata rowMetadata = context.getRowMetadata();
    final String sourceColumnName = context.getColumnName();
    String prefix;
    if (parameters.get(MODE_PARAMETER).equals(OTHER_COLUMN_MODE)) {
        final ColumnMetadata selectedColumn = rowMetadata.getById(parameters.get(SELECTED_COLUMN_PARAMETER));
        prefix = selectedColumn.getName();
    } else {
        prefix = parameters.get(CONSTANT_VALUE);
    }
    additionalColumns.add(ActionsUtils.additionalColumn().withName(sourceColumnName + APPENDIX + prefix).withType(Type.BOOLEAN));
    return additionalColumns;
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5