use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class ActionTestWorkbench method test.
public static void test(Collection<DataSetRow> input, AnalyzerService analyzerService, ActionRegistry actionRegistry, RunnableAction... actions) {
final List<RunnableAction> allActions = new ArrayList<>();
Collections.addAll(allActions, actions);
final DataSet dataSet = new DataSet();
final RowMetadata rowMetadata = input.iterator().next().getRowMetadata();
final DataSetMetadata dataSetMetadata = new DataSetMetadata();
dataSetMetadata.setRowMetadata(rowMetadata);
dataSet.setMetadata(dataSetMetadata);
dataSet.setRecords(input.stream());
final TestOutputNode outputNode = new TestOutputNode(input);
Pipeline pipeline = //
Pipeline.Builder.builder().withActionRegistry(actionRegistry).withInitialMetadata(rowMetadata, //
true).withActions(//
allActions).withAnalyzerService(analyzerService).withStatisticsAdapter(//
new StatisticsAdapter(40)).withOutput(//
() -> outputNode).build();
pipeline.execute(dataSet);
// Some tests rely on the metadata changes in the provided metadata so set back modified columns in row metadata
// (although this should be avoided in tests).
// TODO Make this method return the modified metadata iso. setting modified columns.
rowMetadata.setColumns(outputNode.getMetadata().getColumns());
for (DataSetRow dataSetRow : input) {
dataSetRow.setRowMetadata(rowMetadata);
}
}
use of org.talend.dataprep.api.dataset.RowMetadata 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.RowMetadata in project data-prep by Talend.
the class CompareDatesTest method simple_equals_result_with_column.
@Test
public void simple_equals_result_with_column() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "02/01/2012");
values.put("0001", "02/01/2012");
RowMetadata rowMetadata = new RowMetadata();
rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
rowMetadata.addColumn(createMetadata("0001", "first update", Type.DATE, "statistics_MM_dd_yyyy.json"));
final DataSetRow row = new DataSetRow(rowMetadata, values);
parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.OTHER_COLUMN_MODE);
parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0001");
parameters.put(CompareDates.COMPARE_MODE, CompareDates.EQ);
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
//
Assertions.assertThat(row.values()).hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "02/01/2012"), //
MapEntry.entry("0001", "02/01/2012"), MapEntry.entry("0002", "true"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class CompareDatesTest method test_apply_in_newcolumn.
@Test
public void test_apply_in_newcolumn() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "02/01/2012");
values.put("0001", "02/28/1973");
RowMetadata rowMetadata = new RowMetadata();
rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
rowMetadata.addColumn(createMetadata("0001", "first update", Type.DATE, "statistics_MM_dd_yyyy.json"));
final DataSetRow row = new DataSetRow(rowMetadata, values);
parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.OTHER_COLUMN_MODE);
parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0001");
parameters.put(CompareDates.COMPARE_MODE, CompareDates.GT);
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
//
Assertions.assertThat(row.values()).hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "02/01/2012"), //
MapEntry.entry("0001", "02/28/1973"), MapEntry.entry("0002", "true"));
}
use of org.talend.dataprep.api.dataset.RowMetadata in project data-prep by Talend.
the class CompareDatesTest method compare_date_with_empty_should_have_empty_result.
@Test
public void compare_date_with_empty_should_have_empty_result() throws Exception {
// given
final Map<String, String> values = new HashMap<>();
values.put("0000", "02/01/2012");
values.put("0001", "");
RowMetadata rowMetadata = new RowMetadata();
rowMetadata.addColumn(createMetadata("0000", "last update", Type.DATE, "statistics_MM_dd_yyyy.json"));
rowMetadata.addColumn(createMetadata("0001", "first update", Type.DATE, "statistics_MM_dd_yyyy.json"));
final DataSetRow row = new DataSetRow(rowMetadata, values);
parameters.put(CompareDates.MODE_PARAMETER, OtherColumnParameters.OTHER_COLUMN_MODE);
parameters.put(OtherColumnParameters.SELECTED_COLUMN_PARAMETER, "0001");
parameters.put(CompareDates.COMPARE_MODE, CompareDates.EQ);
// when
ActionTestWorkbench.test(row, actionRegistry, factory.create(action, parameters));
// then
//
Assertions.assertThat(row.values()).hasSize(//
3).containsExactly(//
MapEntry.entry("0000", "02/01/2012"), //
MapEntry.entry("0001", ""), MapEntry.entry("0002", ""));
}
Aggregations