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);
}
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);
}
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);
}
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));
}
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));
}
Aggregations