use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class TransMetaTest method testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam.
@Test
public void testGetPreviousStepsWhenStreamLookupStepPassedShouldClearCacheAndCallFindPreviousStepsWithFalseParam() {
TransMeta transMeta = mock(TransMeta.class);
StepMeta stepMeta = new StepMeta("stream_lookup_id", "stream_lookup_name", new StreamLookupMeta());
List<StepMeta> expectedResult = new ArrayList<>();
List<StepMeta> invalidResult = new ArrayList<>();
expectedResult.add(new StepMeta("correct_mock", "correct_mock", new TextFileOutputMeta()));
invalidResult.add(new StepMeta("incorrect_mock", "incorrect_mock", new TextFileOutputMeta()));
doNothing().when(transMeta).clearPreviousStepCache();
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(false))).thenReturn(expectedResult);
when(transMeta.findPreviousSteps(any(StepMeta.class), eq(true))).thenReturn(invalidResult);
when(transMeta.getPreviousSteps(any())).thenCallRealMethod();
List<StepMeta> actualResult = transMeta.getPreviousSteps(stepMeta);
verify(transMeta, times(1)).clearPreviousStepCache();
assertEquals(expectedResult, actualResult);
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class CheckSumTest method buildHexadecimalChecksumTrans.
private Trans buildHexadecimalChecksumTrans(int checkSumType, boolean compatibilityMode, boolean oldChecksumBehaviour) throws Exception {
// Create a new transformation...
TransMeta transMeta = new TransMeta();
transMeta.setName(getClass().getName());
// Create a CheckSum Step
String checkSumStepname = "CheckSum";
CheckSumMeta meta = new CheckSumMeta();
// Set the compatibility mode and other required fields
meta.setCompatibilityMode(compatibilityMode);
meta.setResultFieldName("hex");
meta.setCheckSumType(checkSumType);
meta.setResultType(CheckSumMeta.result_TYPE_HEXADECIMAL);
meta.setFieldName(new String[] { "test" });
meta.setOldChecksumBehaviour(oldChecksumBehaviour);
String checkSumPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, meta);
StepMeta checkSumStep = new StepMeta(checkSumPluginPid, checkSumStepname, meta);
transMeta.addStep(checkSumStep);
// Create a Dummy step
String dummyStepname = "Output";
DummyTransMeta dummyMeta = new DummyTransMeta();
String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
transMeta.addStep(dummyStep);
// Create a hop from CheckSum to Output
TransHopMeta hop = new TransHopMeta(checkSumStep, dummyStep);
transMeta.addTransHop(hop);
return new Trans(transMeta);
}
use of org.pentaho.di.trans.step.StepMeta in project pentaho-kettle by pentaho.
the class Spoon method refreshStepsSubtree.
private void refreshStepsSubtree(TreeItem tiRootName, TransMeta meta, GUIResource guiResource) {
TreeItem tiStepTitle = createTreeItem(tiRootName, STRING_STEPS, guiResource.getImageFolder());
// Put the steps below it.
for (int i = 0; i < meta.nrSteps(); i++) {
StepMeta stepMeta = meta.getStep(i);
if (stepMeta.isMissing()) {
continue;
}
PluginInterface stepPlugin = PluginRegistry.getInstance().findPluginWithId(StepPluginType.class, stepMeta.getStepID());
if (!filterMatch(stepMeta.getName())) {
continue;
}
Image stepIcon = guiResource.getImagesStepsSmall().get(stepPlugin.getIds()[0]);
if (stepIcon == null) {
stepIcon = guiResource.getImageFolder();
}
TreeItem tiStep = createTreeItem(tiStepTitle, stepMeta.getName(), stepIcon);
if (stepMeta.isShared()) {
tiStep.setFont(guiResource.getFontBold());
}
if (!stepMeta.isDrawn()) {
tiStep.setForeground(guiResource.getColorDarkGray());
}
}
}
use of org.pentaho.di.trans.step.StepMeta 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.step.StepMeta 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);
}
}
}
}
}
Aggregations