Search in sources :

Example 66 with StreamInterface

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

the class FilterRowsMeta method handleStreamSelection.

/**
 * When an optional stream is selected, this method is called to handled the ETL metadata implications of that.
 *
 * @param stream
 *          The optional stream to handle.
 */
public void handleStreamSelection(StreamInterface stream) {
    // This step targets another step.
    // Make sure that we don't specify the same step for true and false...
    // If the user requests false, we blank out true and vice versa
    // 
    List<StreamInterface> targets = getStepIOMeta().getTargetStreams();
    int index = targets.indexOf(stream);
    if (index == 0) {
        // True
        // 
        StepMeta falseStep = targets.get(1).getStepMeta();
        if (falseStep != null && falseStep.equals(stream.getStepMeta())) {
            targets.get(1).setStepMeta(null);
        }
    }
    if (index == 1) {
        // False
        // 
        StepMeta trueStep = targets.get(0).getStepMeta();
        if (trueStep != null && trueStep.equals(stream.getStepMeta())) {
            targets.get(0).setStepMeta(null);
        }
    }
}
Also used : StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 67 with StreamInterface

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

the class JavaFilterMeta method check.

public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space, Repository repository, IMetaStore metaStore) {
    CheckResult cr;
    String error_message = "";
    List<StreamInterface> targetStreams = getStepIOMeta().getTargetStreams();
    if (targetStreams.get(0).getStepname() != null && targetStreams.get(1).getStepname() != null) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.BothTrueAndFalseStepSpecified"), stepMeta);
        remarks.add(cr);
    } else if (targetStreams.get(0).getStepname() == null && targetStreams.get(1).getStepname() == null) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.NeitherTrueAndFalseStepSpecified"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.PlsSpecifyBothTrueAndFalseStep"), stepMeta);
        remarks.add(cr);
    }
    if (targetStreams.get(0).getStepname() != null) {
        int trueTargetIdx = Const.indexOfString(targetStreams.get(0).getStepname(), output);
        if (trueTargetIdx < 0) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.TargetStepInvalid", "true", targetStreams.get(0).getStepname()), stepMeta);
            remarks.add(cr);
        }
    }
    if (targetStreams.get(1).getStepname() != null) {
        int falseTargetIdx = Const.indexOfString(targetStreams.get(1).getStepname(), output);
        if (falseTargetIdx < 0) {
            cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.TargetStepInvalid", "false", targetStreams.get(1).getStepname()), stepMeta);
            remarks.add(cr);
        }
    }
    if (Utils.isEmpty(condition)) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.NoConditionSpecified"), stepMeta);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.ConditionSpecified"), stepMeta);
    }
    remarks.add(cr);
    // Look up fields in the input stream <prev>
    if (prev != null && prev.size() > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.StepReceivingFields", prev.size() + ""), stepMeta);
        remarks.add(cr);
    // What fields are used in the condition?
    // TODO: verify condition, parse it
    // 
    } else {
        error_message = BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.CouldNotReadFieldsFromPreviousStep") + Const.CR;
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, error_message, stepMeta);
        remarks.add(cr);
    }
    // See if we have input streams leading to this step!
    if (input.length > 0) {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.StepReceivingInfoFromOtherSteps"), stepMeta);
        remarks.add(cr);
    } else {
        cr = new CheckResult(CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(PKG, "JavaFilterMeta.CheckResult.NoInputReceivedFromOtherSteps"), stepMeta);
        remarks.add(cr);
    }
}
Also used : CheckResult(org.pentaho.di.core.CheckResult) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 68 with StreamInterface

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

the class JobExecutorMeta method handleStreamSelection.

/**
 * When an optional stream is selected, this method is called to handled the ETL metadata implications of that.
 *
 * @param stream
 *          The optional stream to handle.
 */
@Override
public void handleStreamSelection(StreamInterface stream) {
    // This step targets another step.
    // Make sure that we don't specify the same step for more than 1 target...
    // 
    List<StreamInterface> targets = getStepIOMeta().getTargetStreams();
    int index = targets.indexOf(stream);
    StepMeta step = targets.get(index).getStepMeta();
    switch(index) {
        case 0:
            setExecutionResultTargetStepMeta(step);
            break;
        case 1:
            setResultRowsTargetStepMeta(step);
            break;
        case 2:
            setResultFilesTargetStepMeta(step);
            break;
        default:
            break;
    }
}
Also used : StepMeta(org.pentaho.di.trans.step.StepMeta) BaseStepMeta(org.pentaho.di.trans.step.BaseStepMeta) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 69 with StreamInterface

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

the class FuzzyMatchTest method testReadLookupValues.

@Test
public void testReadLookupValues() throws Exception {
    FuzzyMatchData data = spy(new FuzzyMatchData());
    data.indexOfCachedFields = new int[2];
    data.minimalDistance = 0;
    data.maximalDistance = 5;
    FuzzyMatchMeta meta = spy(new FuzzyMatchMeta());
    meta.setOutputMatchField("I don't want NPE here!");
    data.readLookupValues = true;
    fuzzyMatch = new FuzzyMatchHandler(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    fuzzyMatch.init(meta, data);
    RowSet lookupRowSet = mockHelper.getMockInputRowSet(binaryLookupRows);
    fuzzyMatch.addRowSetToInputRowSets(mockHelper.getMockInputRowSet(binaryRows));
    fuzzyMatch.addRowSetToInputRowSets(lookupRowSet);
    fuzzyMatch.rowset = lookupRowSet;
    RowMetaInterface rowMetaInterface = new RowMeta();
    ValueMetaInterface valueMeta = new ValueMetaString("field1");
    valueMeta.setStorageMetadata(new ValueMetaString("field1"));
    valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
    rowMetaInterface.addValueMeta(valueMeta);
    when(lookupRowSet.getRowMeta()).thenReturn(rowMetaInterface);
    when(meta.getLookupField()).thenReturn("field1");
    when(meta.getMainStreamField()).thenReturn("field1");
    fuzzyMatch.setInputRowMeta(rowMetaInterface.clone());
    when(meta.getAlgorithmType()).thenReturn(1);
    StepIOMetaInterface stepIOMetaInterface = mock(StepIOMetaInterface.class);
    when(meta.getStepIOMeta()).thenReturn(stepIOMetaInterface);
    StreamInterface streamInterface = mock(StreamInterface.class);
    List<StreamInterface> streamInterfaceList = new ArrayList<StreamInterface>();
    streamInterfaceList.add(streamInterface);
    when(streamInterface.getStepMeta()).thenReturn(mockHelper.stepMeta);
    when(stepIOMetaInterface.getInfoStreams()).thenReturn(streamInterfaceList);
    fuzzyMatch.processRow(meta, data);
    Assert.assertEquals(rowMetaInterface.getString(row3B, 0), data.outputRowMeta.getString(fuzzyMatch.resultRow, 1));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) ArrayList(java.util.ArrayList) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Example 70 with StreamInterface

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

the class TransExecutorMetaTest method thirdStreamIsExecutionResultFiles.

@Test
public void thirdStreamIsExecutionResultFiles() throws Exception {
    StreamInterface stream = mockStream();
    StepIOMetaInterface stepIo = mockStepIo(stream, 2);
    TransExecutorMeta meta = new TransExecutorMeta();
    meta = spy(meta);
    when(meta.getStepIOMeta()).thenReturn(stepIo);
    doCallRealMethod().when(meta).handleStreamSelection(any(StreamInterface.class));
    meta.handleStreamSelection(stream);
    assertEquals(stream.getStepMeta(), meta.getResultFilesTargetStepMeta());
}
Also used : StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Aggregations

StreamInterface (org.pentaho.di.trans.step.errorhandling.StreamInterface)84 KettleException (org.pentaho.di.core.exception.KettleException)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)19 StepIOMetaInterface (org.pentaho.di.trans.step.StepIOMetaInterface)19 StepMeta (org.pentaho.di.trans.step.StepMeta)19 Stream (org.pentaho.di.trans.step.errorhandling.Stream)10 TableItem (org.eclipse.swt.widgets.TableItem)8 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)8 Test (org.junit.Test)7 CheckResult (org.pentaho.di.core.CheckResult)7 KettleRowException (org.pentaho.di.core.exception.KettleRowException)7 BaseStepMeta (org.pentaho.di.trans.step.BaseStepMeta)7 ArrayList (java.util.ArrayList)6 TransHopMeta (org.pentaho.di.trans.TransHopMeta)6 StepIOMeta (org.pentaho.di.trans.step.StepIOMeta)6 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)5 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)5 Point (org.pentaho.di.core.gui.Point)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)5