Search in sources :

Example 96 with ColumnMetadata

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

the class ReorderColumnTest 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)

Example 97 with ColumnMetadata

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

the class TypeChangeTest method test_apply_inplace.

@Test
public void test_apply_inplace() throws Exception {
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final ColumnMetadata column = row.getRowMetadata().getById("0002");
    assertThat(column.getType()).isEqualTo("string");
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 98 with ColumnMetadata

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

the class TypeChangeTest method should_not_accept_any_type_to_avoid_transformation_to_be_in_transfo_list.

@Test
public void should_not_accept_any_type_to_avoid_transformation_to_be_in_transfo_list() {
    // given
    final DomainChange domainChange = new DomainChange();
    for (final Type type : Type.values()) {
        final ColumnMetadata columnMetadata = // 
        ColumnMetadata.Builder.column().type(// 
        type).computedId(// 
        "0002").domain(// 
        "FR_BEER").domainFrequency(// 
        1).domainLabel(// 
        "French Beer").build();
        // when
        final boolean accepted = domainChange.acceptField(columnMetadata);
        // then
        assertThat(accepted).isTrue();
    }
}
Also used : Type(org.talend.dataprep.api.type.Type) ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 99 with ColumnMetadata

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

the class TypeChangeTest method should_reset_domain.

@Test
public void should_reset_domain() throws Exception {
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    final ColumnMetadata column = row.getRowMetadata().getById("0002");
    assertThat(column.getDomain()).isEqualTo("");
    assertThat(column.getDomainLabel()).isEqualTo("");
    assertThat(column.getDomainFrequency()).isEqualTo(0);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 100 with ColumnMetadata

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

the class DistanceConverterTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() {
    // given
    Map<String, String> rowContent = new HashMap<>();
    rowContent.put("0000", "David");
    rowContent.put("0001", "1.0");
    final DataSetRow row1 = new DataSetRow(rowContent);
    row1.setTdpId(123L);
    final Map<String, String> parameters = new HashMap<>();
    parameters.put(ImplicitParameters.SCOPE.getKey().toLowerCase(), "column");
    parameters.put("column_id", "0001");
    parameters.put("from_unit", DistanceEnum.KILOMETER.name());
    parameters.put("to_unit", DistanceEnum.MILE.name());
    parameters.put("precision", "9");
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(Collections.singletonList(row1), actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("1.0", row1.get("0001"));
    assertEquals("0.621371192", row1.get("0002"));
    ColumnMetadata expected = ColumnMetadata.Builder.column().id(2).name("0001_in_MILE").type(Type.DOUBLE).build();
    ColumnMetadata actual = row1.getRowMetadata().getById("0002");
    assertEquals(expected, actual);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) 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