Search in sources :

Example 81 with ColumnMetadata

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

the class TrimTest method test_apply_in_newcolumn.

@Test
public void test_apply_in_newcolumn() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", " the beatles ");
    final DataSetRow row = new DataSetRow(values);
    DataSetRow expectedRow = getRow(" the beatles ", "the beatles");
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
    // then
    assertEquals(expectedRow, row);
    ColumnMetadata expected = ColumnMetadata.Builder.column().id(1).name("0000_trim").type(Type.STRING).build();
    ColumnMetadata actual = row.getRowMetadata().getById("0001");
    assertEquals(expected, actual);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) HashMap(java.util.HashMap) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 82 with ColumnMetadata

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

the class TemperaturesConverterTest 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", "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_temperature", CELSIUS.name());
    parameters.put("to_temperature", FAHRENHEIT.name());
    parameters.put("precision", "0");
    parameters.put(ActionsUtils.CREATE_NEW_COLUMN, "true");
    // when
    ActionTestWorkbench.test(Collections.singletonList(row1), actionRegistry, factory.create(action, parameters));
    // then
    assertEquals("0", row1.get("0001"));
    assertEquals("32", row1.get("0002"));
    ColumnMetadata expected = ColumnMetadata.Builder.column().id(2).name("0001_in_Fahrenheit").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)

Example 83 with ColumnMetadata

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

the class LookupTest method cacheUsStates.

private void cacheUsStates() {
    LightweightExportableDataSet usStates = new LightweightExportableDataSet();
    ColumnMetadata[] columnArrays = { ColumnMetadata.Builder.column().name("Postal").domain("US_STATE").type(Type.STRING).build(), ColumnMetadata.Builder.column().name("State").domain("US_STATE").type(Type.STRING).build(), ColumnMetadata.Builder.column().name("Capital").domain("CITY").type(Type.STRING).build() };
    List<ColumnMetadata> columns = Arrays.stream(columnArrays).collect(Collectors.toList());
    usStates.setMetadata(new RowMetadata(columns));
    Map<String, String>[] rows = new HashMap[5];
    rows[0] = getValuesMap("GA", "Georgia", "Atlanta");
    rows[1] = getValuesMap("FL", "Florida", "Tallahassee");
    rows[2] = getValuesMap("IL", "Illinois", "Springfield");
    rows[3] = getValuesMap("TX", "Texas", "Austin");
    rows[4] = getValuesMap("CA", "California", "Sacramento");
    Arrays.stream(rows).forEach(r -> usStates.addRecord((String) r.get("0000"), r));
    LookupDatasetsManager.put("us_states", usStates);
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) LightweightExportableDataSet(org.talend.dataprep.api.dataset.row.LightweightExportableDataSet)

Example 84 with ColumnMetadata

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

the class StandardizeInvalidTest method should_not_accept_column.

@Test
public void should_not_accept_column() {
    // no semantic
    ColumnMetadata column = ColumnMetadata.Builder.column().id(0).name("name").type(Type.STRING).build();
    assertFalse(action.acceptField(column));
}
Also used : ColumnMetadata(org.talend.dataprep.api.dataset.ColumnMetadata) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 85 with ColumnMetadata

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

the class StandardizeInvalidTest 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