Search in sources :

Example 41 with RowMetadata

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

the class CompareDatesTest method simple_not_greater_result_with_constant.

@Test
public void simple_not_greater_result_with_constant() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "02/01/2012");
    RowMetadata rowMetadata = new RowMetadata();
    rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
    final DataSetRow row = new DataSetRow(rowMetadata, values);
    parameters.put(CompareDates.CONSTANT_VALUE, "02/02/2012");
    parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.CONSTANT_MODE);
    parameters.put(CompareDates.COMPARE_MODE, CompareDates.GT);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    // 
    Assertions.assertThat(row.values()).hasSize(// 
    2).containsExactly(// 
    MapEntry.entry("0000", "02/01/2012"), MapEntry.entry("0001", "false"));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 42 with RowMetadata

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

the class CompareDatesTest method compare_empty_with_empty_should_have_empty_result.

@Test
public void compare_empty_with_empty_should_have_empty_result() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "");
    values.put("0001", "");
    RowMetadata rowMetadata = new RowMetadata();
    rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
    rowMetadata.addColumn(createMetadata("0001", "first update", Type.DATE, "statistics_MM_dd_yyyy.json"));
    final DataSetRow row = new DataSetRow(rowMetadata, values);
    parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.OTHER_COLUMN_MODE);
    parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0001");
    parameters.put(CompareDates.COMPARE_MODE, CompareDates.EQ);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    // 
    Assertions.assertThat(row.values()).hasSize(// 
    3).containsExactly(// 
    MapEntry.entry("0000", ""), // 
    MapEntry.entry("0001", ""), MapEntry.entry("0002", ""));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 43 with RowMetadata

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

the class CompareDatesTest method simple_greater_result_with_constant_with_invalid_dates_row.

@Test
public void simple_greater_result_with_constant_with_invalid_dates_row() throws Exception {
    // given
    final Map<String, String> firstRowValues = new HashMap<>();
    firstRowValues.put("0000", "02/01/2012");
    RowMetadata rowMetadata = new RowMetadata();
    rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
    parameters.put(CompareDates.CONSTANT_VALUE, "02/21/2008");
    parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.CONSTANT_MODE);
    parameters.put(CompareDates.COMPARE_MODE, CompareDates.GT);
    final Map<String, String> secondRowvalues = new HashMap<>();
    secondRowvalues.put("0000", "Beer");
    final Map<String, String> thirdRowvalues = new HashMap<>();
    thirdRowvalues.put("0000", "02/01/2001");
    List<DataSetRow> rows = // 
    Arrays.asList(// 
    new DataSetRow(rowMetadata, firstRowValues), // 
    new DataSetRow(rowMetadata, secondRowvalues), new DataSetRow(rowMetadata, thirdRowvalues));
    // when
    ActionTestWorkbench.test(rows, actionRegistry, factory.create(action, parameters));
    // then
    // 
    Assertions.assertThat(rows.get(0).values()).hasSize(// 
    2).containsExactly(// 
    MapEntry.entry("0000", "02/01/2012"), MapEntry.entry("0001", "true"));
    // 
    Assertions.assertThat(rows.get(1).values()).hasSize(// 
    2).containsExactly(// 
    MapEntry.entry("0000", "Beer"), MapEntry.entry("0001", ""));
    // 
    Assertions.assertThat(rows.get(2).values()).hasSize(// 
    2).containsExactly(// 
    MapEntry.entry("0000", "02/01/2001"), MapEntry.entry("0001", "false"));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 44 with RowMetadata

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

the class CompareDatesTest method simple_greater_result_with_constant.

@Test
public void simple_greater_result_with_constant() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "02/01/2012");
    RowMetadata rowMetadata = new RowMetadata();
    rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
    final DataSetRow row = new DataSetRow(rowMetadata, values);
    parameters.put(CompareDates.CONSTANT_VALUE, "02/21/2008");
    parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.CONSTANT_MODE);
    parameters.put(CompareDates.COMPARE_MODE, CompareDates.GT);
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    // 
    Assertions.assertThat(row.values()).hasSize(// 
    2).containsExactly(// 
    MapEntry.entry("0000", "02/01/2012"), MapEntry.entry("0001", "true"));
    final ColumnMetadata expected = ColumnMetadata.Builder.column().id(1).name("last update_gt_02/21/2008?").type(Type.BOOLEAN).build();
    ColumnMetadata actual = row.getRowMetadata().getById("0001");
    assertEquals(expected, actual);
}
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)

Example 45 with RowMetadata

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

the class DomainChangeTest method init.

@Before
public void init() {
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "");
    values.put("0002", "Something");
    row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    ColumnMetadata columnMetadata = rowMetadata.getById("0002");
    columnMetadata.setType(Type.INTEGER.getName());
    columnMetadata.setDomain("FR_BEER");
    columnMetadata.setDomainFrequency(1);
    columnMetadata.setDomainLabel("French Beer");
    parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put(ImplicitParameters.COLUMN_ID.getKey().toLowerCase(), "0002");
    parameters.put(NEW_DOMAIN_ID_PARAMETER_KEY, "AUS_BEER");
    parameters.put(NEW_DOMAIN_LABEL_PARAMETER_KEY, "Australian Beer");
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Before(org.junit.Before)

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