Search in sources :

Example 1 with RowsToResultMeta

use of org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzer method linkResultFieldToSubTrans.

/**
 * Checks to see if the sub trans has any RowToResult steps in it.
 * If so, it will link the fields it outputs to the fields created by this step and are sent to the
 * "target step for output rows".
 *
 * @param streamFieldNode stream field node sent to the step defined as "target step for output rows"
 * @param subTransMeta TransMeta of the transformation to be executed by the TransExecutor step
 * @param subTransNode IMetaverseNode representing the sub-transformation to be executed
 * @param descriptor Descriptor to use as a basis for any nodes created
 */
protected void linkResultFieldToSubTrans(IMetaverseNode streamFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
    List<StepMeta> steps = subTransMeta.getSteps();
    if (!CollectionUtils.isEmpty(steps)) {
        for (StepMeta step : steps) {
            if (step.getStepMetaInterface() instanceof RowsToResultMeta) {
                RowsToResultMeta rtrm = (RowsToResultMeta) step.getStepMetaInterface();
                // Create a new descriptor for the RowsToResult step.
                IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(step.getName(), DictionaryConst.NODE_TYPE_TRANS_STEP, subTransNode, descriptor.getContext());
                // Create a new node for the step, to be used as the parent of the the field we want to link to
                IMetaverseNode subTransStepNode = createNodeFromDescriptor(stepDescriptor);
                try {
                    RowMetaInterface rowMetaInterface = rtrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
                    for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
                        String field = rowMetaInterface.getFieldNames()[i];
                        if (streamFieldNode.getName().equals(field)) {
                            // Create the descriptor for the trans field that is derived from the incoming result field
                            IComponentDescriptor stepFieldDescriptor = new MetaverseComponentDescriptor(field, DictionaryConst.NODE_TYPE_TRANS_FIELD, subTransStepNode, descriptor.getContext());
                            // Create the node
                            // IMetaverseNode subTransField = createNodeFromDescriptor( stepFieldDescriptor );
                            IMetaverseNode subTransField = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), StepAnalyzer.NONE, false);
                            // Add the link
                            metaverseBuilder.addLink(subTransField, DictionaryConst.LINK_DERIVES, streamFieldNode);
                            // no need to keep looking for a match on field name, we just handled it.
                            continue;
                        }
                    }
                } catch (KettleStepException e) {
                    log.warn("Could not get step fields of RowsToResult step in sub transformation - " + subTransMeta.getName(), e);
                }
            }
        }
    }
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) KettleStepException(org.pentaho.di.core.exception.KettleStepException) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsToResultMeta(org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Example 2 with RowsToResultMeta

use of org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta in project pentaho-metaverse by pentaho.

the class TransExecutorStepAnalyzerTest method testLinkResultFieldToSubTrans.

@Test
public void testLinkResultFieldToSubTrans() throws Exception {
    IMetaverseNode childTransNode = mock(IMetaverseNode.class);
    IMetaverseNode fieldNode = mock(IMetaverseNode.class);
    when(fieldNode.getName()).thenReturn(resultsFieldNames[1]);
    List<StepMeta> childTransSteps = new ArrayList<StepMeta>();
    StepMeta dummy = mock(StepMeta.class);
    when(dummy.getStepMetaInterface()).thenReturn(mock(DummyTransMeta.class));
    childTransSteps.add(dummy);
    StepMeta parentStepMeta = mock(StepMeta.class);
    when(parentStepMeta.getParentTransMeta()).thenReturn(parentTransMeta);
    StepMeta rowsFromResult = mock(StepMeta.class);
    RowsToResultMeta mockRowsToResultMeta = mock(RowsToResultMeta.class);
    when(rowsFromResult.getStepMetaInterface()).thenReturn(mockRowsToResultMeta);
    when(mockRowsToResultMeta.getParentStepMeta()).thenReturn(parentStepMeta);
    when(mockRowsToResultMeta.getName()).thenReturn("stepName");
    childTransSteps.add(rowsFromResult);
    RowMetaInterface rowMetaInterface = mock(RowMetaInterface.class);
    when(parentTransMeta.getStepFields(any(StepMeta.class))).thenReturn(rowMetaInterface);
    when(rowMetaInterface.getFieldNames()).thenReturn(resultsFieldNames);
    when(childTransMeta.getSteps()).thenReturn(childTransSteps);
    IMetaverseNode subFieldNode = mock(IMetaverseNode.class);
    doReturn(subFieldNode).when(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq(StepAnalyzer.NONE), eq(false));
    spyAnalyzer.linkResultFieldToSubTrans(fieldNode, childTransMeta, childTransNode, descriptor);
    verify(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq(StepAnalyzer.NONE), eq(false));
    verify(builder).addLink(eq(subFieldNode), eq(DictionaryConst.LINK_DERIVES), eq(fieldNode));
}
Also used : IComponentDescriptor(org.pentaho.metaverse.api.IComponentDescriptor) IMetaverseNode(org.pentaho.metaverse.api.IMetaverseNode) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) RowsToResultMeta(org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Aggregations

RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)2 StepMeta (org.pentaho.di.trans.step.StepMeta)2 RowsToResultMeta (org.pentaho.di.trans.steps.rowstoresult.RowsToResultMeta)2 IComponentDescriptor (org.pentaho.metaverse.api.IComponentDescriptor)2 IMetaverseNode (org.pentaho.metaverse.api.IMetaverseNode)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 KettleStepException (org.pentaho.di.core.exception.KettleStepException)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)1 MetaverseComponentDescriptor (org.pentaho.metaverse.api.MetaverseComponentDescriptor)1