Search in sources :

Example 1 with ActionNode

use of org.talend.dataprep.transformation.pipeline.node.ActionNode in project data-prep by Talend.

the class StepNodeTransformerTest method shouldCreateStepNode.

@Test
public void shouldCreateStepNode() throws Exception {
    // given
    Node node = // 
    NodeBuilder.from(// 
    new CompileNode(null, null)).to(// 
    new ActionNode(null, null)).build();
    // when
    final Node processed = StepNodeTransformer.transform(node, asList(ROOT, STEP), s -> null);
    // then
    final Class[] expectedClasses = { SourceNode.class, StepNode.class };
    final NodeClassVisitor visitor = new NodeClassVisitor();
    processed.accept(visitor);
    assertThat(visitor.traversedClasses, hasItems(expectedClasses));
}
Also used : CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) StepNode(org.talend.dataprep.transformation.pipeline.node.StepNode) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) Test(org.junit.Test)

Example 2 with ActionNode

use of org.talend.dataprep.transformation.pipeline.node.ActionNode in project data-prep by Talend.

the class StepNodeTransformerTest method shouldFailCreateStepNode.

@Test(expected = IllegalArgumentException.class)
public void shouldFailCreateStepNode() throws Exception {
    // given
    Node node = // 
    NodeBuilder.from(// 
    new CompileNode(null, null)).to(// 
    new ActionNode(null, null)).build();
    // then
    StepNodeTransformer.transform(node, emptyList(), s -> null);
}
Also used : CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) StepNode(org.talend.dataprep.transformation.pipeline.node.StepNode) SourceNode(org.talend.dataprep.transformation.pipeline.node.SourceNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) BasicNode(org.talend.dataprep.transformation.pipeline.node.BasicNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) Test(org.junit.Test)

Example 3 with ActionNode

use of org.talend.dataprep.transformation.pipeline.node.ActionNode in project data-prep by Talend.

the class ActionNodesBuilder method build.

/**
 * Build the actions pipeline
 */
public Node build() {
    final StatisticsNodesBuilder statisticsNodesBuilder = StatisticsNodesBuilder.builder().analyzerService(// 
    analyzerService).actionRegistry(// 
    actionRegistry).statisticsAdapter(// 
    statisticsAdapter).allowSchemaAnalysis(// 
    allowSchemaAnalysis).actions(// 
    actions).columns(initialMetadata.getColumns());
    final NodeBuilder builder = NodeBuilder.source();
    // unless we don't have initial metadata or we explicitly ask it
    if (needStatisticsBefore || initialMetadata.getColumns().isEmpty()) {
        LOGGER.debug("No initial metadata submitted for transformation, computing new one.");
        builder.to(statisticsNodesBuilder.buildPreStatistics());
    }
    // transformation context is the parent of every action context
    // it will hold all the action context
    // that makes it the perfect entry point to clean up all the contexts
    final TransformationContext context = new TransformationContext();
    // * an action node
    for (final RunnableAction nextAction : actions) {
        // some actions need fresh statistics
        // in those cases, we gather the rows in a reservoir node that triggers statistics computation
        // before dispatching each row to the next node
        final Node neededReservoir = statisticsNodesBuilder.buildIntermediateStatistics(nextAction);
        if (neededReservoir != null) {
            builder.to(neededReservoir);
        }
        final DataSetRowAction rowAction = nextAction.getRowAction();
        builder.to(new CompileNode(nextAction, context.create(rowAction, initialMetadata)));
        builder.to(new ActionNode(nextAction, context.in(rowAction)));
    }
    // when it is explicitly asked and the actions changes the columns
    if (needStatisticsAfter) {
        builder.to(statisticsNodesBuilder.buildPostStatistics());
    }
    // cleanup all contexts after all actions
    builder.to(new CleanUpNode(context));
    return builder.build();
}
Also used : DataSetRowAction(org.talend.dataprep.transformation.api.action.DataSetRowAction) CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) CleanUpNode(org.talend.dataprep.transformation.pipeline.node.CleanUpNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) CompileNode(org.talend.dataprep.transformation.pipeline.node.CompileNode) Node(org.talend.dataprep.transformation.pipeline.Node) CleanUpNode(org.talend.dataprep.transformation.pipeline.node.CleanUpNode) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext)

Example 4 with ActionNode

use of org.talend.dataprep.transformation.pipeline.node.ActionNode in project data-prep by Talend.

the class UpdatedStepVisitor method visitStepNode.

@Override
public void visitStepNode(StepNode stepNode) {
    stepNode.getEntryNode().accept(new Visitor() {

        @Override
        public void visitAction(ActionNode actionNode) {
            final ActionContext.ActionStatus status = actionNode.getActionContext().getActionStatus();
            final Step step = stepNode.getStep();
            switch(status) {
                case NOT_EXECUTED:
                case CANCELED:
                    LOGGER.debug("Not updating metadata for {} (action ended with status {}).", step.getId(), status);
                    step.setRowMetadata(null);
                    break;
                case OK:
                case DONE:
                    LOGGER.debug("Keeping metadata {} (action ended with status {}).", step.getId(), status);
                    break;
            }
            preparationUpdater.update(step.id(), actionNode.getActionContext().getRowMetadata());
        }
    });
    super.visitStepNode(stepNode);
}
Also used : Visitor(org.talend.dataprep.transformation.pipeline.Visitor) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) Step(org.talend.dataprep.api.preparation.Step)

Example 5 with ActionNode

use of org.talend.dataprep.transformation.pipeline.node.ActionNode in project data-prep by Talend.

the class UpdatedStepVisitorTest method setUp.

@Before
public void setUp() throws Exception {
    actionContext = new ActionContext(new TransformationContext());
    entryNode = new ActionNode(new RunnableAction((row, context) -> row), actionContext);
}
Also used : RunnableAction(org.talend.dataprep.transformation.actions.common.RunnableAction) ActionNode(org.talend.dataprep.transformation.pipeline.node.ActionNode) ActionContext(org.talend.dataprep.transformation.api.action.context.ActionContext) TransformationContext(org.talend.dataprep.transformation.api.action.context.TransformationContext) Before(org.junit.Before)

Aggregations

ActionNode (org.talend.dataprep.transformation.pipeline.node.ActionNode)8 CompileNode (org.talend.dataprep.transformation.pipeline.node.CompileNode)6 Test (org.junit.Test)5 BasicNode (org.talend.dataprep.transformation.pipeline.node.BasicNode)5 SourceNode (org.talend.dataprep.transformation.pipeline.node.SourceNode)5 StepNode (org.talend.dataprep.transformation.pipeline.node.StepNode)5 RunnableAction (org.talend.dataprep.transformation.actions.common.RunnableAction)2 TransformationContext (org.talend.dataprep.transformation.api.action.context.TransformationContext)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Before (org.junit.Before)1 Step (org.talend.dataprep.api.preparation.Step)1 DataSetRowAction (org.talend.dataprep.transformation.api.action.DataSetRowAction)1 ActionContext (org.talend.dataprep.transformation.api.action.context.ActionContext)1 Node (org.talend.dataprep.transformation.pipeline.Node)1 Visitor (org.talend.dataprep.transformation.pipeline.Visitor)1 CleanUpNode (org.talend.dataprep.transformation.pipeline.node.CleanUpNode)1