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);
}
}
}
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);
}
}
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;
}
}
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));
}
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());
}
Aggregations