Search in sources :

Example 6 with Statistics

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

the class FillWithDateIfInvalidTest method should_not_fill_non_valid_datetime.

@Test
public void should_not_fill_non_valid_datetime() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "09/07/2015 13:31:35");
    values.put("0002", "Something");
    final Statistics statistics = getStatistics(this.getClass().getResourceAsStream("fillInvalidDateTimeAction_statistics.json"));
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.DATE.getName());
    rowMetadata.getById("0001").setStatistics(statistics);
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidDateTimeAction.json"));
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("09/07/2015 13:31:35", row.get("0001"));
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 7 with Statistics

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

the class FillWithDateIfInvalidTest method should_fill_non_valid_datetime.

@Test
public void should_fill_non_valid_datetime() throws Exception {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final Statistics statistics = getStatistics(this.getClass().getResourceAsStream("fillInvalidDateTimeAction_statistics.json"));
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.DATE.getName());
    rowMetadata.getById("0001").setStatistics(statistics);
    Map<String, String> parameters = ActionMetadataTestUtils.parseParameters(this.getClass().getResourceAsStream("fillInvalidDateTimeAction.json"));
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("09/07/2015 13:31:36", row.get("0001"));
}
Also used : HashMap(java.util.HashMap) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) ChangeDatePatternTest(org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest) Test(org.junit.Test)

Example 8 with Statistics

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

the class CopyColumnTest method test_TDP_567_with_force_false.

@Test
public void test_TDP_567_with_force_false() throws Exception {
    List<ColumnMetadata> input = new ArrayList<>();
    final ColumnMetadata original = createMetadata("0001", "column");
    original.setStatistics(new Statistics());
    SemanticDomain semanticDomain = new SemanticDomain("mountain_goat", "Mountain goat pale pale", 1);
    original.setDomain("beer");
    original.setDomainFrequency(1);
    original.setDomainLabel("the best beer");
    original.setDomainForced(false);
    original.setTypeForced(false);
    original.setSemanticDomains(Collections.singletonList(semanticDomain));
    input.add(original);
    RowMetadata rowMetadata = new RowMetadata(input);
    assertThat(rowMetadata.getColumns()).isNotNull().isNotEmpty().hasSize(1);
    final DataSetRow row = new DataSetRow(rowMetadata);
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    List<ColumnMetadata> actual = row.getRowMetadata().getColumns();
    assertThat(actual).isNotNull().isNotEmpty().hasSize(2);
    assertEquals(actual.get(1).getStatistics(), original.getStatistics());
    // 
    assertThat(actual.get(1)).isEqualToComparingOnlyGivenFields(original, "domain", "domainLabel", "domainFrequency", "domainForced", "typeForced");
    // 
    assertThat(actual.get(1).getSemanticDomains()).isNotNull().isNotEmpty().contains(semanticDomain);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 9 with Statistics

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

the class CopyColumnTest method should_copy_statistics.

@Test
public void should_copy_statistics() throws Exception {
    // given
    final ColumnMetadata original = createMetadata("0001", "column");
    original.setStatistics(new Statistics());
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(original);
    final RowMetadata rowMetadata = new RowMetadata(input);
    final ColumnMetadata transformed = createMetadata("0002", "column");
    original.setStatistics(new Statistics());
    final List<ColumnMetadata> expected = new ArrayList<>();
    expected.add(createMetadata("0001", "column"));
    expected.add(transformed);
    // when
    ActionTestWorkbench.test(rowMetadata, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expected.get(1).getStatistics(), original.getStatistics());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 10 with Statistics

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

the class CopyColumnTest method test_TDP_567_with_force_true.

@Test
public void test_TDP_567_with_force_true() throws Exception {
    List<ColumnMetadata> input = new ArrayList<>();
    final ColumnMetadata original = createMetadata("0001", "column");
    original.setStatistics(new Statistics());
    SemanticDomain semanticDomain = new SemanticDomain("mountain_goat", "Mountain goat pale pale", 1);
    original.setDomain("beer");
    original.setDomainFrequency(1);
    original.setDomainLabel("the best beer");
    original.setDomainForced(true);
    original.setTypeForced(true);
    original.setSemanticDomains(Collections.singletonList(semanticDomain));
    input.add(original);
    RowMetadata rowMetadata = new RowMetadata(input);
    assertThat(rowMetadata.getColumns()).isNotNull().isNotEmpty().hasSize(1);
    final DataSetRow row = new DataSetRow(rowMetadata);
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    List<ColumnMetadata> actual = row.getRowMetadata().getColumns();
    assertThat(actual).isNotNull().isNotEmpty().hasSize(2);
    assertEquals(actual.get(1).getStatistics(), original.getStatistics());
    // 
    assertThat(actual.get(1)).isEqualToComparingOnlyGivenFields(original, "domain", "domainLabel", "domainFrequency", "domainForced", "typeForced");
    // 
    assertThat(actual.get(1).getSemanticDomains()).isNotNull().isNotEmpty().contains(semanticDomain);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) SemanticDomain(org.talend.dataprep.api.dataset.statistics.SemanticDomain) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Statistics(org.talend.dataprep.api.dataset.statistics.Statistics) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Aggregations

Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)15 Test (org.junit.Test)10 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)10 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)9 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)7 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)3 HashMap (java.util.HashMap)2 PatternFrequency (org.talend.dataprep.api.dataset.statistics.PatternFrequency)2 ChangeDatePatternTest (org.talend.dataprep.transformation.actions.date.ChangeDatePatternTest)2 TemporalField (java.time.temporal.TemporalField)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)1 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)1 Quality (org.talend.dataprep.api.dataset.Quality)1 DataSetBaseTest (org.talend.dataprep.dataset.DataSetBaseTest)1 ActionMetadataTestUtils.setStatistics (org.talend.dataprep.transformation.actions.ActionMetadataTestUtils.setStatistics)1 JulianDayConverter (org.talend.dataquality.converters.JulianDayConverter)1