Search in sources :

Example 36 with RowMetadata

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);
    }
}
Also used : StatisticsAdapter(org.talend.dataprep.dataset.StatisticsAdapter) DataSet(org.talend.dataprep.api.dataset.DataSet) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetMetadata(org.talend.dataprep.api.dataset.DataSetMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Pipeline(org.talend.dataprep.transformation.pipeline.Pipeline)

Example 37 with 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);
}
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 38 with RowMetadata

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"));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 39 with RowMetadata

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"));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Example 40 with RowMetadata

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", ""));
}
Also used : RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)199 Test (org.junit.Test)130 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)112 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)87 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)68 HashMap (java.util.HashMap)48 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)20 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)19 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)18 ArrayList (java.util.ArrayList)16 DataSet (org.talend.dataprep.api.dataset.DataSet)11 List (java.util.List)9 Statistics (org.talend.dataprep.api.dataset.statistics.Statistics)9 Before (org.junit.Before)7 SemanticDomain (org.talend.dataprep.api.dataset.statistics.SemanticDomain)6 Preparation (org.talend.dataprep.api.preparation.Preparation)6 Response (com.jayway.restassured.response.Response)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 Logger (org.slf4j.Logger)5