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);
}
}
}
}
}
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));
}
Aggregations