Search in sources :

Example 21 with ColumnMetadata

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

the class DateParserTest method shouldNotComputePatternFromDQBecauseEmptyValue.

@Test(expected = DateTimeException.class)
public void shouldNotComputePatternFromDQBecauseEmptyValue() {
    final ColumnMetadata column = ActionMetadataTestUtils.getColumn(Type.DATE);
    action.guessPattern("", column);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test)

Example 22 with ColumnMetadata

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

the class DateParserTest method shouldComputePatternFromDQ.

@Test
public void shouldComputePatternFromDQ() {
    final ColumnMetadata column = ActionMetadataTestUtils.getColumn(Type.DATE);
    assertEquals(new DatePattern("dd/MM/yyyy", 1), action.guessPattern("01/02/2015", column));
    assertEquals(new DatePattern("d/M/yyyy", 1), action.guessPattern("1/2/2015", column));
    assertEquals(new DatePattern("yyyy-MM-dd", 1), action.guessPattern("2015-01-02", column));
    assertEquals(new DatePattern("9999", 1), action.guessPattern("2015", column));
    assertEquals(new DatePattern("MMMM d yyyy", 1), action.guessPattern("July 14 2015", column));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test)

Example 23 with ColumnMetadata

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

the class DateParserTest method shouldUpdateColumnStatisticsWithNewDatePattern.

@Test
public void shouldUpdateColumnStatisticsWithNewDatePattern() {
    // given
    ColumnMetadata column = ActionMetadataTestUtils.getColumn(Type.DATE);
    column.getStatistics().getPatternFrequencies().add(new PatternFrequency("yyyy", 19));
    // when
    action.guessAndParse("01/02/2015", column);
    // then
    final List<PatternFrequency> actual = column.getStatistics().getPatternFrequencies();
    assertEquals(2, actual.size());
    assertEquals(new PatternFrequency("dd/MM/yyyy", 1), actual.get(1));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) PatternFrequency(org.talend.dataprep.api.dataset.statistics.PatternFrequency) Test(org.junit.Test)

Example 24 with ColumnMetadata

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

the class ExtractDateTokensTest method should_update_metadata.

@Test
public void should_update_metadata() throws IOException {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(createMetadata("0000"));
    input.add(createMetadata("0001"));
    input.add(createMetadata("0002"));
    final RowMetadata rowMetadata = new RowMetadata(input);
    ObjectMapper mapper = new ObjectMapper();
    final Statistics statistics = mapper.reader(Statistics.class).readValue(getDateTestJsonAsStream("statistics_yyyy-MM-dd.json"));
    input.get(1).setStatistics(statistics);
    // when
    ActionTestWorkbench.test(rowMetadata, actionRegistry, factory.create(action, parameters));
    // then
    assertNotNull(rowMetadata.getById("0003"));
    assertNotNull(rowMetadata.getById("0004"));
    assertNotNull(rowMetadata.getById("0005"));
    assertNotNull(rowMetadata.getById("0006"));
    assertNull(rowMetadata.getById("0007"));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) ActionMetadataTestUtils.setStatistics(org.talend.dataprep.transformation.actions.ActionMetadataTestUtils.setStatistics) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 25 with ColumnMetadata

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

the class ExtractDateTokensTest method testAdapt.

@Test
public void testAdapt() throws Exception {
    assertThat(action.adapt((ColumnMetadata) null), is(action));
    ColumnMetadata column = column().name("myColumn").id(0).type(Type.STRING).build();
    assertThat(action.adapt(column), is(action));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test)

Aggregations

ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)320 Test (org.junit.Test)217 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)115 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)86 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)80 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)48 InputStream (java.io.InputStream)25 Type (org.talend.dataprep.api.type.Type)23 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)22 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)17 IOException (java.io.IOException)14 TDPException (org.talend.dataprep.exception.TDPException)14 Schema (org.talend.dataprep.schema.Schema)14 Autowired (org.springframework.beans.factory.annotation.Autowired)13 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)12 DataSetServiceTest (org.talend.dataprep.dataset.service.DataSetServiceTest)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)10