Search in sources :

Example 6 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class ActionParserTest method should_return_expected_actions.

@Test
public void should_return_expected_actions() throws IOException {
    String json = IOUtils.toString(ActionParserTest.class.getResourceAsStream("actions.json"), UTF_8);
    // when
    List<RunnableAction> actualActions = actionParser.parse(json);
    // then
    assertTrue(actualActions.size() == 1);
    Action actionParsed = actualActions.get(0);
    assertEquals("lookup", actionParsed.getName());
}
Also used : Action(org.talend.dataprep.api.preparation.Action) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) Test(org.junit.Test)

Example 7 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction 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 8 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class ClearInvalidTest method should_not_clear_because_valid.

@Test
public void should_not_clear_because_valid() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.STRING.getName());
    final Map<String, Object> expectedValues = new HashMap<>();
    expectedValues.put("0000", "David Bowie");
    expectedValues.put("0001", "N");
    expectedValues.put("0002", "Something");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 9 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class ClearInvalidTest method test_apply_inplace.

@Test
public void test_apply_inplace() {
    // given
    final Map<String, String> values = new HashMap<>();
    values.put("0000", "David Bowie");
    values.put("0001", "N");
    values.put("0002", "Something");
    final DataSetRow row = new DataSetRow(values);
    row.setInvalid("0001");
    final RowMetadata rowMetadata = row.getRowMetadata();
    rowMetadata.getById("0001").setType(Type.STRING.getName());
    final Map<String, Object> expectedValues = new LinkedHashMap<>();
    expectedValues.put("__tdpInvalid", "0001");
    expectedValues.put("0000", "David Bowie");
    expectedValues.put("0001", "");
    expectedValues.put("0002", "Something");
    // when
    final RunnableAction runnableAction = factory.create(action, parameters);
    final ActionContext context = new ActionContext(new TransformationContext(), rowMetadata);
    context.setParameters(parameters);
    runnableAction.getRowAction().apply(row, context);
    // then
    assertEquals(expectedValues, row.values());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test) AbstractMetadataBaseTest(org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)

Example 10 with RunnableAction

use of org.talend.dataprep.transformation.actions.common.RunnableAction in project data-prep by Talend.

the class PipelineTest method testCompileAction.

@Test
public void testCompileAction() throws Exception {
    // Given
    final RunnableAction mockAction = new RunnableAction() {

        @Override
        public DataSetRowAction getRowAction() {
            return new DataSetRowAction() {

                @Override
                public void compile(ActionContext actionContext) {
                    actionContext.get("ExecutedCompile", p -> true);
                }

                @Override
                public DataSetRow apply(DataSetRow dataSetRow, ActionContext context) {
                    return dataSetRow;
                }
            };
        }
    };
    final ActionContext actionContext = new ActionContext(new TransformationContext());
    final Node node = NodeBuilder.source().to(new CompileNode(mockAction, actionContext)).to(output).build();
    final RowMetadata rowMetadata = new RowMetadata();
    final DataSetRow row = new DataSetRow(rowMetadata);
    // when
    assertFalse(actionContext.has("ExecutedCompile"));
    node.exec().receive(row, rowMetadata);
    // then
    assertTrue(actionContext.has("ExecutedCompile"));
    assertTrue(actionContext.get("ExecutedCompile"));
}
Also used : DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) RowMetadata(org.talend.dataprep.api.dataset.RowMetadata) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) DataSetRow(org.talend.dataprep.api.dataset.row.DataSetRow) Test(org.junit.Test)

Aggregations

RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)32 Test (org.junit.Test)23 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)22 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)21 DataSetRow (org.talend.dataprep.api.dataset.row.DataSetRow)20 RowMetadata (org.talend.dataprep.api.dataset.RowMetadata)18 HashMap (java.util.HashMap)15 AbstractMetadataBaseTest (org.talend.dataprep.transformation.actions.AbstractMetadataBaseTest)14 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)6 ActionDefinition (org.talend.dataprep.api.action.ActionDefinition)4 ColumnMetadata (org.talend.dataprep.api.dataset.ColumnMetadata)4 Action (org.talend.dataprep.api.preparation.Action)4 ArrayList (java.util.ArrayList)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 Before (org.junit.Before)3 DataSet (org.talend.dataprep.api.dataset.DataSet)3 DataSetMetadata (org.talend.dataprep.api.dataset.DataSetMetadata)3 CoreMatchers (org.hamcrest.CoreMatchers)2