use of org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzer method linkUsedFieldToSubTrans.
/**
* Checks to see if the sub trans has any RowFromResult steps in it.
* If so, it will link the original field node to the fields created in the RowFromResult step in the sub trans
*
* @param originalFieldNode incoming stream field node to the TransExecutorStep
* @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
*/
protected void linkUsedFieldToSubTrans(IMetaverseNode originalFieldNode, TransMeta subTransMeta, IMetaverseNode subTransNode, IComponentDescriptor descriptor) {
List<StepMeta> steps = subTransMeta.getSteps();
if (!CollectionUtils.isEmpty(steps)) {
for (StepMeta step : steps) {
if (step.getStepMetaInterface() instanceof RowsFromResultMeta) {
RowsFromResultMeta rfrm = (RowsFromResultMeta) step.getStepMetaInterface();
// Create a new descriptor for the RowsFromResult step.
IComponentDescriptor stepDescriptor = new MetaverseComponentDescriptor(StepAnalyzer.NONE, 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 = rfrm.getParentStepMeta().getParentTransMeta().getStepFields(step);
for (int i = 0; i < rowMetaInterface.getFieldNames().length; i++) {
String field = rowMetaInterface.getFieldNames()[i];
if (originalFieldNode.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 = createFieldNode(stepFieldDescriptor, rowMetaInterface.getValueMeta(i), step.getName(), false);
// Add the link
metaverseBuilder.addLink(originalFieldNode, DictionaryConst.LINK_DERIVES, subTransField);
// 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 RowsFromResult step in sub transformation - " + subTransMeta.getName(), e);
}
}
}
}
}
use of org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta in project pentaho-metaverse by pentaho.
the class TransExecutorStepAnalyzerTest method testLinkUsedFieldToSubTrans.
@Test
public void testLinkUsedFieldToSubTrans() throws Exception {
IMetaverseNode childTransNode = mock(IMetaverseNode.class);
IMetaverseNode originalFieldNode = mock(IMetaverseNode.class);
when(originalFieldNode.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 rowsFromResult = mock(StepMeta.class);
RowsFromResultMeta mockRowsFromResultMeta = mock(RowsFromResultMeta.class);
when(rowsFromResult.getStepMetaInterface()).thenReturn(mockRowsFromResultMeta);
when(rowsFromResult.getName()).thenReturn("stepName");
childTransSteps.add(rowsFromResult);
when(mockRowsFromResultMeta.getFieldname()).thenReturn(resultsFieldNames);
StepMeta rowsParentStepMeta = mock(StepMeta.class);
TransMeta rowsParentTransMeta = mock(TransMeta.class);
RowMetaInterface rmiRows = mock(RowMetaInterface.class);
when(mockRowsFromResultMeta.getParentStepMeta()).thenReturn(rowsParentStepMeta);
when(rowsParentStepMeta.getParentTransMeta()).thenReturn(rowsParentTransMeta);
when(rowsParentTransMeta.getStepFields(rowsFromResult)).thenReturn(rmiRows);
when(rmiRows.getFieldNames()).thenReturn(resultsFieldNames);
ValueMetaInterface vmi = mock(ValueMetaInterface.class);
when(rmiRows.getValueMeta(anyInt())).thenReturn(vmi);
when(childTransMeta.getSteps()).thenReturn(childTransSteps);
IMetaverseNode subFieldNode = mock(IMetaverseNode.class);
doReturn(subFieldNode).when(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq("stepName"), eq(false));
spyAnalyzer.linkUsedFieldToSubTrans(originalFieldNode, childTransMeta, childTransNode, descriptor);
verify(spyAnalyzer).createFieldNode(any(IComponentDescriptor.class), any(ValueMetaInterface.class), eq("stepName"), eq(false));
verify(builder).addLink(eq(originalFieldNode), eq(DictionaryConst.LINK_DERIVES), eq(subFieldNode));
}
Aggregations