Search in sources :

Example 6 with DataSetRow

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

the class DateCalendarConverterTest method testConversionJapaneseToISO_ValidDateWithoutEra.

@Test
public void testConversionJapaneseToISO_ValidDateWithoutEra() {
    // given
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "0008/10/29");
    final DataSetRow row = new DataSetRow(rowContent);
    row.getRowMetadata().getColumns().get(1).getStatistics().getPatternFrequencies().add(new PatternFrequency("yyyy/MM/dd", 1));
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put(COLUMN_ID.getKey(), "0001");
    parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.JAPANESE.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    // The date pattern does not contain G, the input cannot be parsed
    assertEquals("0008/10/29", row.get("0001"));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 7 with DataSetRow

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

the class DateCalendarConverterTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() {
    Map<String, String> rowContent = new HashMap<>();
    // row1
    rowContent.put("0000", "David");
    rowContent.put("0001", "1970-01-01");
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.getRowMetadata().getColumns().get(1).getStatistics().getPatternFrequencies().add(new PatternFrequency("yyyy-MM-dd", 1));
    // row 2
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "0001-01-01");
    final DataSetRow row2 = new DataSetRow(rowContent);
    // row 3
    rowContent = new HashMap<>();
    rowContent.put("0000", "Michel");
    rowContent.put("0001", "");
    final DataSetRow row3 = new DataSetRow(rowContent);
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put("column_id", "0001");
    parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.JULIAN_DAY.name());
    parameters.put("create_new_column", "true");
    // when
    ActionTestWorkbench.test(Arrays.asList(row1, row2, row3), actionRegistry, factory.create(action, parameters));
    // then
    // assert that original column is unchanged:
    assertEquals("1970-01-01", row1.get("0001"));
    assertEquals("0001-01-01", row2.get("0001"));
    assertEquals("", row3.get("0001"));
    // assert that new column is created:
    assertEquals("2440588", row1.get("0002"));
    assertEquals("1721426", row2.get("0002"));
    assertEquals("", row3.get("0002"));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 8 with DataSetRow

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

the class DateCalendarConverterTest method testConversion_only_output_custom.

@Test
public void testConversion_only_output_custom() throws IOException {
    // given
    final DataSetRow row = builder().with(value("toto").type(Type.STRING).name("recipe")).with(value("10/29/1996").type(Type.DATE).name("last update").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING).name("who")).build();
    parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put(COLUMN_ID.getKey().toLowerCase(), "0001");
    parameters.put(FROM_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.ISO.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.HIJRI.name());
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow = getRow("toto", HijrahStr3, "tata");
    assertEquals(expectedRow.values(), row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 9 with DataSetRow

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

the class ExtractDateTokensTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() throws Exception {
    // given
    final DataSetRow row = // 
    builder().with(// 
    value("toto").type(Type.STRING)).with(value("04/25/1999").type(Type.DATE).statistics(// 
    getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING)).build();
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "toto");
    expectedValues.put("0001", "04/25/1999");
    expectedValues.put("0006", "1999");
    expectedValues.put("0005", "4");
    expectedValues.put("0004", "0");
    expectedValues.put("0003", "0");
    expectedValues.put("0002", "tata");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 10 with DataSetRow

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

the class ExtractDateTokensTest method should_process_row_very_wrong_pattern.

/**
 * To test with a date that does not match any of the pattern present in the stats
 */
@Test
public void should_process_row_very_wrong_pattern() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "toto");
    values.put("0001", "NA");
    values.put("0002", "tata");
    final DataSetRow row = new DataSetRow(values);
    setStatistics(row, "0001", getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"));
    final Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("0000", "toto");
    expectedValues.put("0001", "NA");
    expectedValues.put("0003", "");
    expectedValues.put("0004", "");
    expectedValues.put("0005", "");
    expectedValues.put("0006", "");
    expectedValues.put("0002", "tata");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedValues, row.values());
}
Also used : DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)729 Test (org.junit.Test)688 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)518 HashMap (java.util.HashMap)235 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)111 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)81 LinkedHashMap (java.util.LinkedHashMap)45 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)21 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)16 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)16 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)14 ArrayList (java.util.ArrayList)13 ChangeDatePatternTest (org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 AbstractTransformerWriterTest (org.talend.dataprep.transformation.api.transformer.AbstractTransformerWriterTest)12 List (java.util.List)11 PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)11 DataSet (org.talend.dataprep.api.dataset.DataSet)10 Stream (java.util.stream.Stream)6 TDPException (org.talend.dataprep.exception.TDPException)6