use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class ClearMatchingTest method should_clear_because_pattern_match.
@Test
public void should_clear_because_pattern_match() throws Exception {
// given
final Map<String, String> firstRowValues = new HashMap<>();
firstRowValues.put("0000", "David Bowie");
firstRowValues.put("0001", "N");
firstRowValues.put("0002", "Something");
final Map<String, String> secondRowValues = new HashMap<>();
secondRowValues.put("0000", "Beer");
secondRowValues.put("0001", "T");
secondRowValues.put("0002", "NotSomething");
final Map<String, String> thirdRowValues = new HashMap<>();
thirdRowValues.put("0000", "Wine");
thirdRowValues.put("0001", "True");
thirdRowValues.put("0002", "Somethin");
List<DataSetRow> rows = //
Arrays.asList(//
new DataSetRow(firstRowValues), //
new DataSetRow(secondRowValues), new DataSetRow(thirdRowValues));
for (DataSetRow row : rows) {
final RowMetadata rowMetadata = row.getRowMetadata();
rowMetadata.getById("0002").setType(Type.STRING.getName());
}
parameters.put(ClearMatching.VALUE_PARAMETER, generateJson(".*Something", ReplaceOnValueHelper.REGEX_MODE));
// when
ActionTestWorkbench.test(rows, actionRegistry, factory.create(action, parameters));
// then
//
Assertions.assertThat(rows.get(0).values()).isNotEmpty().hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "David Bowie"), //
MapEntry.entry("0001", "N"), MapEntry.entry("0002", ""));
//
Assertions.assertThat(rows.get(1).values()).isNotEmpty().hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "Beer"), //
MapEntry.entry("0001", "T"), MapEntry.entry("0002", ""));
//
Assertions.assertThat(rows.get(2).values()).isNotEmpty().hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "Wine"), //
MapEntry.entry("0001", "True"), MapEntry.entry("0002", "Somethin"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class CopyColumnTest 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", "steps"));
input.add(createMetadata("0002", "last_update"));
final RowMetadata rowMetadata = new RowMetadata(input);
final List<ColumnMetadata> expectedColumns = new ArrayList<>();
expectedColumns.add(createMetadata("0000", "recipe"));
expectedColumns.add(createMetadata("0001", "steps"));
expectedColumns.add(createMetadata("0003", "steps_copy"));
expectedColumns.add(createMetadata("0002", "last_update"));
final RowMetadata expected = new RowMetadata(expectedColumns);
// when
final DataSetRow row = new DataSetRow(rowMetadata);
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
assertEquals(expected, row.getRowMetadata());
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class CopyColumnTest method test_TDP_1184.
/**
* Test with non-consecutive columns ids. This can occurs after some column deletion.
*/
@Test
public void test_TDP_1184() {
// given
final List<ColumnMetadata> input = new ArrayList<>();
input.add(columnBaseBuilder().name("recipe").type(Type.STRING).build());
input.add(columnBaseBuilder().name("steps").type(Type.STRING).build());
input.add(columnBaseBuilder().name("last update").type(Type.STRING).build());
input.add(columnBaseBuilder().name("column to delete").type(Type.STRING).build());
final RowMetadata rowMetadata = new RowMetadata(input);
// when
rowMetadata.deleteColumnById("0003");
final DataSetRow row = new DataSetRow(rowMetadata);
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
final List<ColumnMetadata> actual = row.getRowMetadata().getColumns();
assertEquals(actual.size(), 4);
final ColumnMetadata copiedColumn = row.getRowMetadata().getById("0004");
assertNotNull(copiedColumn);
assertEquals("steps_copy", copiedColumn.getName());
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class ExtractEmailDomain method compile.
@Override
public void compile(ActionContext context) {
super.compile(context);
if (ActionsUtils.doesCreateNewColumn(context.getParameters(), true)) {
final List<ActionsUtils.AdditionalColumn> additionalColumns = new ArrayList<>();
final RowMetadata rowMetadata = context.getRowMetadata();
final ColumnMetadata column = rowMetadata.getById(context.getColumnId());
additionalColumns.add(ActionsUtils.additionalColumn().withKey(LOCAL).withName(column.getName() + LOCAL));
additionalColumns.add(ActionsUtils.additionalColumn().withKey(DOMAIN).withName(column.getName() + DOMAIN));
ActionsUtils.createNewColumn(context, additionalColumns);
}
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class Contains method getAdditionalColumns.
protected List<ActionsUtils.AdditionalColumn> getAdditionalColumns(ActionContext context) {
final List<ActionsUtils.AdditionalColumn> additionalColumns = new ArrayList<>();
final Map<String, String> parameters = context.getParameters();
final RowMetadata rowMetadata = context.getRowMetadata();
final String sourceColumnName = context.getColumnName();
String prefix;
if (parameters.get(MODE_PARAMETER).equals(OTHER_COLUMN_MODE)) {
final ColumnMetadata selectedColumn = rowMetadata.getById(parameters.get(SELECTED_COLUMN_PARAMETER));
prefix = selectedColumn.getName();
} else {
prefix = parameters.get(CONSTANT_VALUE);
}
additionalColumns.add(ActionsUtils.additionalColumn().withName(sourceColumnName + APPENDIX + prefix).withType(Type.BOOLEAN));
return additionalColumns;
}
Aggregations