Search in sources :

Example 16 with PatternFrequency

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

the class TrailingSpaceRuleTest method setUp.

@Before
public void setUp() throws Exception {
    trailingSpaceRule = StringRules.trailingSpaceRule();
    stringColumn.getStatistics().getPatternFrequencies().add(new PatternFrequency("AaaA", 10));
    stringWithSpacesColumn.getStatistics().getPatternFrequencies().add(new PatternFrequency(" Aaa ", 10));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) Before(org.junit.Before)

Example 17 with PatternFrequency

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

the class UpperCaseRuleTest method setUp.

@Before
public void setUp() throws Exception {
    upperCaseRule = StringRules.upperCaseRule();
    stringColumn.getStatistics().getPatternFrequencies().add(new PatternFrequency("aaaa", 10));
    stringUpperCaseColumn.getStatistics().getPatternFrequencies().add(new PatternFrequency("AAAA", 10));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) Before(org.junit.Before)

Example 18 with PatternFrequency

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

the class DateCalendarConverterTest method testConversion.

private void testConversion(String from, DateCalendarConverter.CalendarUnit fromUnit, String fromPattern, String expected, DateCalendarConverter.CalendarUnit toUnit) {
    // given
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    rowContent.put("0001", from);
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.getRowMetadata().getColumns().get(1).getStatistics().getPatternFrequencies().add(new PatternFrequency(fromPattern, 1));
    // row 2
    rowContent = new HashMap<>();
    rowContent.put("0000", "John");
    rowContent.put("0001", "foo");
    final DataSetRow row2 = new DataSetRow(rowContent);
    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, fromUnit.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, toUnit.name());
    // when
    ActionTestWorkbench.test(Arrays.asList(row1, row2), actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expected, row1.get("0001"));
    assertEquals("foo", row2.get("0001"));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow)

Example 19 with PatternFrequency

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

the class DateCalendarConverterTest method testConversionJapaneseToISO_ValidDateWithEra.

@Test
public void testConversionJapaneseToISO_ValidDateWithEra() {
    // given
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    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 G", 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
    // While using ResolverStyle.STRICT, date pattern of input data on Japanese calendar must contain era 'G'
    assertEquals("1996/10/29 AD", 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 20 with PatternFrequency

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

the class DateCalendarConverterTest method testChronologyToJulianDaySameInstance.

/**
 * row1 and row2 should use one instance DateCalendarConverter.Just cover the test code and no assert the Mpa 'dateCalendarConverterMap'.
 * Because the Map is private.
 */
@Test
public void testChronologyToJulianDaySameInstance() {
    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);
    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.ISO.name());
    parameters.put(TO_CALENDAR_TYPE_PARAMETER, DateCalendarConverter.CalendarUnit.JULIAN_DAY.name());
    // when
    ActionTestWorkbench.test(Arrays.asList(row1, row2), actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("2440588", row1.get("0001"));
    assertEquals("1721426", row2.get("0001"));
}
Also used : PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)25 Test (org.junit.Test)14 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)11 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)8 Before (org.junit.Before)7 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)4 HashMap (java.util.HashMap)3 List (java.util.List)3 StringUtils (org.apache.commons.lang.StringUtils)3 CoreMatchers.is (org.hamcrest.CoreMatchers.is)3 Type (org.talend.dataprep.api.type.Type)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Optional (java.util.Optional)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertFalse (org.junit.Assert.assertFalse)2