Search in sources :

Example 26 with ColumnMetadata

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

the class ModifyDateTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() throws Exception {
    // given
    final DataSetRow row1 = // 
    builder().with(// 
    value("toto").type(Type.STRING).name("recipe")).with(// 
    value("04/25/1999").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tata").type(Type.STRING).name("last update")).build();
    final DataSetRow row2 = // 
    builder().with(// 
    value("tata mouche").type(Type.STRING).name("recipe")).with(// 
    value("  ").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("toto pouche").type(Type.STRING).name("last update")).build();
    final DataSetRow row3 = // 
    builder().with(// 
    value("titi louche").type(Type.STRING).name("recipe")).with(// 
    value("culbutoqué").type(Type.DATE).name("recipe").statistics(getDateTestJsonAsStream("statistics_MM_dd_yyyy.json"))).with(// 
    value("tutu couche").type(Type.STRING).name("last update")).build();
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row1, actionRegistry, factory.create(action, parameters));
    ActionTestWorkbench.test(row2, actionRegistry, factory.create(action, parameters));
    ActionTestWorkbench.test(row3, actionRegistry, factory.create(action, parameters));
    // then
    final DataSetRow expectedRow1 = getRow("toto", "04/25/1999", "tata", "04/25/2000");
    assertEquals(expectedRow1.values(), row1.values());
    ColumnMetadata expected1 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual1 = row1.getRowMetadata().getById("0003");
    assertEquals(expected1, actual1);
    final DataSetRow expectedRow2 = getRow("tata mouche", "  ", "toto pouche", "  ");
    assertEquals(expectedRow2.values(), row2.values());
    ColumnMetadata expected2 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual2 = row2.getRowMetadata().getById("0003");
    assertEquals(expected2, actual2);
    final DataSetRow expectedRow3 = getRow("titi louche", "culbutoqué", "tutu couche", "culbutoqué");
    assertEquals(expectedRow3.values(), row3.values());
    ColumnMetadata expected3 = ColumnMetadata.Builder.column().id(3).name("recipe_modified").type(Type.STRING).build();
    ColumnMetadata actual3 = row3.getRowMetadata().getById("0003");
    assertEquals(expected3, actual3);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 27 with ColumnMetadata

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

the class TimestampToDateTest method should_update_metadata.

@Test
public void should_update_metadata() {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(createMetadata("0000", "recipe"));
    input.add(createMetadata("0001", "timestamp"));
    input.add(createMetadata("0002", "last update"));
    final RowMetadata rowMetadata = new RowMetadata(input);
    final List<ColumnMetadata> expected = new ArrayList<>();
    expected.add(createMetadata("0000", "recipe"));
    expected.add(createMetadata("0001", "timestamp"));
    expected.add(createMetadata("0003", "timestamp_as_date", Type.DATE));
    expected.add(createMetadata("0002", "last update"));
    // when
    ActionTestWorkbench.test(rowMetadata, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expected, rowMetadata.getColumns());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Test(org.junit.Test)

Example 28 with ColumnMetadata

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

the class TimestampToDateTest method should_update_metadata_twice.

@Test
public void should_update_metadata_twice() {
    // given
    final List<ColumnMetadata> input = new ArrayList<>();
    input.add(createMetadata("0000", "recipe"));
    input.add(createMetadata("0001", "timestamp"));
    input.add(createMetadata("0002", "last update"));
    final RowMetadata rowMetadata = new RowMetadata(input);
    final List<ColumnMetadata> expected = new ArrayList<>();
    expected.add(createMetadata("0000", "recipe"));
    expected.add(createMetadata("0001", "timestamp"));
    expected.add(createMetadata("0004", "timestamp_as_date", Type.DATE));
    expected.add(createMetadata("0003", "timestamp_as_date", Type.DATE));
    expected.add(createMetadata("0002", "last update"));
    // when
    ActionTestWorkbench.test(rowMetadata, actionRegistry, factory.create(action, parameters), factory.create(action, parameters));
    // then
    assertEquals(expected, rowMetadata.getColumns());
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) Test(org.junit.Test)

Example 29 with ColumnMetadata

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

the class AbsoluteTest method testAdaptFloat.

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

Example 30 with ColumnMetadata

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

the class ChangeNumberFormatTest 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) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

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