Search in sources :

Example 31 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-kettle by pentaho.

the class Spoon method generateFieldMapping.

/**
 * Create a new SelectValues step in between this step and the previous. If the previous fields are not there, no
 * mapping can be made, same with the required fields.
 *
 * @param stepMeta
 *          The target step to map against.
 */
// retry of required fields acquisition
public void generateFieldMapping(TransMeta transMeta, StepMeta stepMeta) {
    try {
        if (stepMeta != null) {
            StepMetaInterface smi = stepMeta.getStepMetaInterface();
            RowMetaInterface targetFields = smi.getRequiredFields(transMeta);
            RowMetaInterface sourceFields = transMeta.getPrevStepFields(stepMeta);
            // Build the mapping: let the user decide!!
            String[] source = sourceFields.getFieldNames();
            for (int i = 0; i < source.length; i++) {
                ValueMetaInterface v = sourceFields.getValueMeta(i);
                source[i] += EnterMappingDialog.STRING_ORIGIN_SEPARATOR + v.getOrigin() + ")";
            }
            String[] target = targetFields.getFieldNames();
            EnterMappingDialog dialog = new EnterMappingDialog(shell, source, target);
            List<SourceToTargetMapping> mappings = dialog.open();
            if (mappings != null) {
                // OK, so we now know which field maps where.
                // This allows us to generate the mapping using a
                // SelectValues Step...
                SelectValuesMeta svm = new SelectValuesMeta();
                svm.allocate(mappings.size(), 0, 0);
                // CHECKSTYLE:Indentation:OFF
                for (int i = 0; i < mappings.size(); i++) {
                    SourceToTargetMapping mapping = mappings.get(i);
                    svm.getSelectFields()[i].setName(sourceFields.getValueMeta(mapping.getSourcePosition()).getName());
                    svm.getSelectFields()[i].setRename(target[mapping.getTargetPosition()]);
                    svm.getSelectFields()[i].setLength(-1);
                    svm.getSelectFields()[i].setPrecision(-1);
                }
                // a new comment. Sincerely yours CO ;)
                // Now that we have the meta-data, create a new step info object
                String stepName = stepMeta.getName() + " Mapping";
                // if
                stepName = transMeta.getAlternativeStepname(stepName);
                // it's already there, rename it.
                StepMeta newStep = new StepMeta("SelectValues", stepName, svm);
                newStep.setLocation(stepMeta.getLocation().x + 20, stepMeta.getLocation().y + 20);
                newStep.setDraw(true);
                transMeta.addStep(newStep);
                addUndoNew(transMeta, new StepMeta[] { newStep }, new int[] { transMeta.indexOfStep(newStep) });
                // Redraw stuff...
                refreshTree();
                refreshGraph();
            }
        } else {
            throw new KettleException("There is no target to do a field mapping against!");
        }
    } catch (KettleException e) {
        new ErrorDialog(shell, "Error creating mapping", "There was an error when Kettle tried to generate a field mapping against the target step", e);
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) EnterMappingDialog(org.pentaho.di.ui.core.dialog.EnterMappingDialog) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) KettleExtensionPoint(org.pentaho.di.core.extension.KettleExtensionPoint) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) SelectValuesMeta(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta) SourceToTargetMapping(org.pentaho.di.core.SourceToTargetMapping)

Example 32 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.

the class TransMetaJsonSerializer method getBaseStepMetaFromStepMeta.

protected BaseStepMeta getBaseStepMetaFromStepMeta(StepMeta stepMeta) {
    // Attempt to discover a BaseStepMeta from the given StepMeta
    BaseStepMeta baseStepMeta = new BaseStepMeta();
    baseStepMeta.setParentStepMeta(stepMeta);
    if (stepMeta != null) {
        StepMetaInterface smi = stepMeta.getStepMetaInterface();
        if (smi instanceof BaseStepMeta) {
            baseStepMeta = (BaseStepMeta) smi;
        }
    }
    return baseStepMeta;
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta)

Example 33 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.

the class StepExternalConsumerRowListenerTest method testStepExternalConsumerRowListener.

@Test
public void testStepExternalConsumerRowListener() throws Exception {
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    BaseStep mockStep = mock(BaseStep.class, withSettings().extraInterfaces(StepInterface.class));
    StepMeta mockStepMeta = mock(StepMeta.class);
    BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
    StepMetaInterface stepMetaInterface = (StepMetaInterface) bsm;
    when(mockStep.getStepMeta()).thenReturn(mockStepMeta);
    when(mockStepMeta.getStepMetaInterface()).thenReturn(stepMetaInterface);
    Trans mockTrans = mock(Trans.class);
    when(mockStep.getTrans()).thenReturn(mockTrans);
    IExecutionProfile executionProfile = mock(IExecutionProfile.class);
    IExecutionData executionData = mock(IExecutionData.class);
    when(executionProfile.getExecutionData()).thenReturn(executionData);
    LineageHolder holder = new LineageHolder();
    holder.setExecutionProfile(executionProfile);
    TransLineageHolderMap.getInstance().putLineageHolder(mockTrans, holder);
    StepExternalConsumerRowListener listener = new StepExternalConsumerRowListener(consumer, mockStep);
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    Object[] row = new Object[0];
    listener.rowReadEvent(rmi, row);
}
Also used : BaseStep(org.pentaho.di.trans.step.BaseStep) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) StepInterface(org.pentaho.di.trans.step.StepInterface) IExecutionData(org.pentaho.metaverse.api.model.IExecutionData) IExecutionProfile(org.pentaho.metaverse.api.model.IExecutionProfile) Trans(org.pentaho.di.trans.Trans) LineageHolder(org.pentaho.metaverse.api.model.LineageHolder) Test(org.junit.Test)

Example 34 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pentaho-metaverse by pentaho.

the class StepExternalResourceConsumerListenerTest method testCallStepExtensionPoint.

@Test
public void testCallStepExtensionPoint() throws Exception {
    StepExternalResourceConsumerListener stepExtensionPoint = new StepExternalResourceConsumerListener();
    stepExtensionPoint.setStepExternalResourceConsumerProvider(MetaverseTestUtils.getStepExternalResourceConsumerProvider());
    StepMetaDataCombi stepCombi = mock(StepMetaDataCombi.class);
    BaseStepMeta bsm = mock(BaseStepMeta.class, withSettings().extraInterfaces(StepMetaInterface.class));
    stepCombi.meta = (StepMetaInterface) bsm;
    stepCombi.step = mock(StepInterface.class);
    stepCombi.stepMeta = mock(StepMeta.class);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    Map<Class<? extends BaseStepMeta>, Set<IStepExternalResourceConsumer>> stepConsumerMap = new StepExternalResourceConsumerProvider().getStepConsumerMap();
    Set<IStepExternalResourceConsumer> consumers = new HashSet<IStepExternalResourceConsumer>();
    stepConsumerMap.put(bsm.getClass(), consumers);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    IStepExternalResourceConsumer consumer = mock(IStepExternalResourceConsumer.class);
    when(consumer.getResourcesFromMeta(Mockito.any())).thenReturn(Collections.emptyList());
    consumers.add(consumer);
    Trans mockTrans = mock(Trans.class);
    when(stepCombi.step.getTrans()).thenReturn(mockTrans);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
    when(consumer.isDataDriven(Mockito.any())).thenReturn(Boolean.TRUE);
    stepExtensionPoint.callExtensionPoint(null, stepCombi);
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) IStepExternalResourceConsumer(org.pentaho.metaverse.api.analyzer.kettle.step.IStepExternalResourceConsumer) StepInterface(org.pentaho.di.trans.step.StepInterface) StepExternalResourceConsumerProvider(org.pentaho.metaverse.analyzer.kettle.step.StepExternalResourceConsumerProvider) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) Trans(org.pentaho.di.trans.Trans) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 35 with StepMetaInterface

use of org.pentaho.di.trans.step.StepMetaInterface in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateIifStep.

/**
 * This method generates a 4 steps for every IIF clause... TODO: replace with one step...
 *
 * @param iifField
 * @param lastStep
 * @param transMeta
 * @return steps
 */
private StepMeta generateIifStep(SQLField iifField, TransMeta transMeta, StepMeta lastStep) {
    IifFunction iif = iifField.getIif();
    // The Filter condition...
    // 
    FilterRowsMeta filterMeta = new FilterRowsMeta();
    filterMeta.setCondition(iifField.getIif().getSqlCondition().getCondition());
    StepMeta filterStep = new StepMeta(iifField.getExpression(), filterMeta);
    filterStep.setLocation(xLocation, 50);
    xLocation += 100;
    filterStep.setDraw(true);
    lastStep = addToTrans(filterStep, transMeta, lastStep);
    // The True and false steps...
    // 
    StepMetaInterface trueMetaInterface;
    ValueMetaInterface valueMeta = iif.getTrueValue().getValueMeta();
    if (iif.isTrueField()) {
        CalculatorMeta trueMeta = new CalculatorMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getTrueValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta trueMeta = new ConstantMeta();
        trueMetaInterface = trueMeta;
        trueMeta.allocate(1);
        // CHECKSTYLE:Indentation:OFF
        trueMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        trueMeta.getFieldType()[0] = iif.getTrueValue().getValueMeta().getTypeDesc();
        trueMeta.getValue()[0] = iif.getTrueValue().toString();
        trueMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
    }
    StepMeta trueStep = new StepMeta("TRUE: " + iifField.getExpression(), trueMetaInterface);
    trueStep.setLocation(xLocation, 50);
    trueStep.setDraw(true);
    lastStep = addToTrans(trueStep, transMeta, filterStep);
    StepMetaInterface falseMetaInterface;
    valueMeta = iif.getFalseValue().getValueMeta();
    if (iif.isFalseField()) {
        CalculatorMeta falseMeta = new CalculatorMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        CalculatorMetaFunction function = new CalculatorMetaFunction();
        function.setFieldName(Const.NVL(iifField.getAlias(), iifField.getField()));
        function.setCalcType(CalculatorMetaFunction.CALC_COPY_OF_FIELD);
        function.setValueType(valueMeta.getType());
        function.setValueLength(valueMeta.getLength());
        function.setValuePrecision(valueMeta.getPrecision());
        function.setFieldA(iif.getFalseValueString());
        function.setConversionMask(valueMeta.getConversionMask());
        falseMeta.getCalculation()[0] = function;
    } else {
        ConstantMeta falseMeta = new ConstantMeta();
        falseMetaInterface = falseMeta;
        falseMeta.allocate(1);
        falseMeta.getFieldName()[0] = Const.NVL(iifField.getAlias(), iifField.getField());
        falseMeta.getFieldType()[0] = iif.getFalseValue().getValueMeta().getTypeDesc();
        falseMeta.getFieldFormat()[0] = valueMeta.getConversionMask();
        falseMeta.getValue()[0] = iif.getFalseValue().toString();
    }
    StepMeta falseStep = new StepMeta("FALSE: " + iifField.getExpression(), falseMetaInterface);
    falseStep.setLocation(xLocation, 150);
    xLocation += 100;
    falseStep.setDraw(true);
    lastStep = addToTrans(falseStep, transMeta, filterStep);
    // specify true/false targets
    List<StreamInterface> targetStreams = filterMeta.getStepIOMeta().getTargetStreams();
    targetStreams.get(0).setSubject(trueStep.getName());
    targetStreams.get(1).setSubject(falseStep.getName());
    filterMeta.searchInfoAndTargetSteps(transMeta.getSteps());
    DummyTransMeta dummyMeta = new DummyTransMeta();
    StepMeta dummyStep = new StepMeta("Collect: " + iifField.getExpression(), dummyMeta);
    dummyStep.setLocation(xLocation, 50);
    xLocation += 100;
    dummyStep.setDraw(true);
    lastStep = addToTrans(dummyStep, transMeta, trueStep);
    transMeta.addTransHop(new TransHopMeta(falseStep, dummyStep));
    return lastStep;
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IifFunction(org.pentaho.di.core.sql.IifFunction) CalculatorMeta(org.pentaho.di.trans.steps.calculator.CalculatorMeta) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ConstantMeta(org.pentaho.di.trans.steps.constant.ConstantMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) CalculatorMetaFunction(org.pentaho.di.trans.steps.calculator.CalculatorMetaFunction) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Aggregations

StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)77 StepMeta (org.pentaho.di.trans.step.StepMeta)40 KettleException (org.pentaho.di.core.exception.KettleException)31 Test (org.junit.Test)22 ArrayList (java.util.ArrayList)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)20 TransMeta (org.pentaho.di.trans.TransMeta)16 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)16 TableItem (org.eclipse.swt.widgets.TableItem)15 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)15 SourceToTargetMapping (org.pentaho.di.core.SourceToTargetMapping)14 Trans (org.pentaho.di.trans.Trans)14 EnterMappingDialog (org.pentaho.di.ui.core.dialog.EnterMappingDialog)14 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)12 Point (org.pentaho.di.core.gui.Point)12 TransHopMeta (org.pentaho.di.trans.TransHopMeta)11 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)11 NotePadMeta (org.pentaho.di.core.NotePadMeta)8 KettleStepException (org.pentaho.di.core.exception.KettleStepException)8 JobEntryInterface (org.pentaho.di.job.entry.JobEntryInterface)8