Search in sources :

Example 1 with StepMeta

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);
}
Also used : TextFileOutputMeta(org.pentaho.di.trans.steps.textfileoutput.TextFileOutputMeta) StreamLookupMeta(org.pentaho.di.trans.steps.streamlookup.StreamLookupMeta) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 2 with StepMeta

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);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 3 with StepMeta

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());
        }
    }
}
Also used : TreeItem(org.eclipse.swt.widgets.TreeItem) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) Image(org.eclipse.swt.graphics.Image) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint)

Example 4 with StepMeta

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);
                }
            }
        }
    }
}
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 5 with StepMeta

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);
                }
            }
        }
    }
}
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) RowsFromResultMeta(org.pentaho.di.trans.steps.rowsfromresult.RowsFromResultMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) MetaverseComponentDescriptor(org.pentaho.metaverse.api.MetaverseComponentDescriptor)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)696 TransMeta (org.pentaho.di.trans.TransMeta)252 Test (org.junit.Test)202 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)178 KettleException (org.pentaho.di.core.exception.KettleException)174 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)156 Trans (org.pentaho.di.trans.Trans)130 TransHopMeta (org.pentaho.di.trans.TransHopMeta)130 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)121 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)121 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)107 StepInterface (org.pentaho.di.trans.step.StepInterface)102 ArrayList (java.util.ArrayList)81 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)81 Point (org.pentaho.di.core.gui.Point)80 FormAttachment (org.eclipse.swt.layout.FormAttachment)76 FormData (org.eclipse.swt.layout.FormData)76 FormLayout (org.eclipse.swt.layout.FormLayout)76 Label (org.eclipse.swt.widgets.Label)76 Shell (org.eclipse.swt.widgets.Shell)76