use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class AppendIT method testAppendStep.
/**
* Test case for Append step. 2 Injector steps to an append step to a dummy step. Rows go in, the order should be as
* defined in the append step.
*/
public void testAppendStep() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("Appendtest");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create an injector step 1...
//
String injectorStepname1 = "injector step 1";
InjectorMeta im1 = new InjectorMeta();
// Set the information of the injector.
String injectorPid1 = registry.getPluginId(StepPluginType.class, im1);
StepMeta injectorStep1 = new StepMeta(injectorPid1, injectorStepname1, im1);
transMeta.addStep(injectorStep1);
//
// create an injector step 2...
//
String injectorStepname2 = "injector step 2";
InjectorMeta im2 = new InjectorMeta();
// Set the information of the injector.
String injectorPid2 = registry.getPluginId(StepPluginType.class, im2);
StepMeta injectorStep2 = new StepMeta(injectorPid2, injectorStepname2, im2);
transMeta.addStep(injectorStep2);
//
// Create an append step
//
String appendName = "append step";
AppendMeta am = new AppendMeta();
List<StreamInterface> infoStreams = am.getStepIOMeta().getInfoStreams();
infoStreams.get(0).setStepMeta(injectorStep1);
infoStreams.get(1).setStepMeta(injectorStep2);
String appendPid = registry.getPluginId(StepPluginType.class, am);
StepMeta append = new StepMeta(appendPid, appendName, am);
transMeta.addStep(append);
TransHopMeta hi2 = new TransHopMeta(injectorStep1, append);
transMeta.addTransHop(hi2);
TransHopMeta hi3 = new TransHopMeta(injectorStep2, append);
transMeta.addTransHop(hi3);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi4 = new TransHopMeta(append, dummyStep1);
transMeta.addTransHop(hi4);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(appendName, 0);
RowStepCollector blockingRc = new RowStepCollector();
si.addRowListener(blockingRc);
si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector dummyRc1 = new RowStepCollector();
si.addRowListener(dummyRc1);
RowProducer rp1 = trans.addRowProducer(injectorStepname1, 0);
RowProducer rp2 = trans.addRowProducer(injectorStepname2, 0);
trans.startThreads();
// add rows to tail step
List<RowMetaAndData> inputList2 = createData2();
Iterator<RowMetaAndData> it2 = inputList2.iterator();
while (it2.hasNext()) {
RowMetaAndData rm = it2.next();
rp2.putRow(rm.getRowMeta(), rm.getData());
}
rp2.finished();
// add rows to head step
List<RowMetaAndData> inputList1 = createData1();
Iterator<RowMetaAndData> it1 = inputList1.iterator();
while (it1.hasNext()) {
RowMetaAndData rm = it1.next();
rp1.putRow(rm.getRowMeta(), rm.getData());
}
rp1.finished();
trans.waitUntilFinished();
// The result should be that first all rows from injector 1 and
// then all rows from injector step 2
List<RowMetaAndData> expectedList = new ArrayList<RowMetaAndData>();
expectedList.addAll(inputList1);
expectedList.addAll(inputList2);
List<RowMetaAndData> resultRows1 = dummyRc1.getRowsWritten();
checkRows(resultRows1, expectedList);
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class AppendMeta method readData.
private void readData(Node stepnode) throws KettleXMLException {
try {
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get(0);
StreamInterface tailStream = infoStreams.get(1);
headStream.setSubject(XMLHandler.getTagValue(stepnode, "head_name"));
tailStream.setSubject(XMLHandler.getTagValue(stepnode, "tail_name"));
} catch (Exception e) {
throw new KettleXMLException(BaseMessages.getString(PKG, "AppendMeta.Exception.UnableToLoadStepInfo"), e);
}
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class MergeRowsIT method testOneRow.
void testOneRow(String transName, String[] referenceValues, String[] comparisonValues, Object[] goldenImageRowValues) throws Exception {
KettleEnvironment.init();
// Create a new transformation...
TransMeta transMeta = new TransMeta();
transMeta.setName(transName);
PluginRegistry registry = PluginRegistry.getInstance();
// Create a merge rows step
String mergeRowsStepName = "merge rows step";
MergeRowsMeta mergeRowsMeta = new MergeRowsMeta();
String mergeRowsStepPid = registry.getPluginId(StepPluginType.class, mergeRowsMeta);
StepMeta mergeRowsStep = new StepMeta(mergeRowsStepPid, mergeRowsStepName, mergeRowsMeta);
transMeta.addStep(mergeRowsStep);
mergeRowsMeta.setKeyFields(new String[] { keyField });
mergeRowsMeta.setValueFields(new String[] { compareField });
mergeRowsMeta.setFlagField(flagField);
List<StreamInterface> infoStreams = mergeRowsMeta.getStepIOMeta().getInfoStreams();
//
// create a reference stream (row generator step)
//
createRowGenerator(transMeta, registry, "reference row generator", referenceValues, mergeRowsStep, mergeRowsMeta, 0);
//
// create a comparison stream (row generator step)
//
createRowGenerator(transMeta, registry, "comparison row generator", comparisonValues, mergeRowsStep, mergeRowsMeta, 1);
// Now execute the transformation
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(mergeRowsStepName, 0);
RowStepCollector endRc = new RowStepCollector();
si.addRowListener(endRc);
trans.startThreads();
trans.waitUntilFinished();
// Now check whether the output is still as we expect.
List<RowMetaAndData> goldenImageRows = createResultData(goldenImageRowValues);
List<RowMetaAndData> resultRows1 = endRc.getRowsWritten();
checkRows(resultRows1, goldenImageRows);
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class MergeRowsIT method createRowGenerator.
void createRowGenerator(TransMeta transMeta, PluginRegistry registry, String stepName, String[] values, StepMeta mergeRowsStep, MergeRowsMeta mergeRowsMeta, int index) {
RowGeneratorMeta rowGeneratorMeta = new RowGeneratorMeta();
String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rowGeneratorMeta);
StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, stepName, rowGeneratorMeta);
transMeta.addStep(rowGeneratorStep);
rowGeneratorMeta.setDefault();
rowGeneratorMeta.setFieldName(fieldName);
rowGeneratorMeta.setFieldType(type);
rowGeneratorMeta.setFieldLength(intDummies);
rowGeneratorMeta.setFieldPrecision(intDummies);
rowGeneratorMeta.setRowLimit("1");
rowGeneratorMeta.setFieldFormat(fieldFormat);
rowGeneratorMeta.setGroup(group);
rowGeneratorMeta.setDecimal(decimal);
rowGeneratorMeta.setCurrency(currency);
rowGeneratorMeta.setEmptyString(setEmptystring);
rowGeneratorMeta.setValue(values);
TransHopMeta hi1 = new TransHopMeta(rowGeneratorStep, mergeRowsStep);
transMeta.addTransHop(hi1);
List<StreamInterface> infoStreams = mergeRowsMeta.getStepIOMeta().getInfoStreams();
StreamInterface infoStream = infoStreams.get(index);
infoStream.setStepMeta(transMeta.findStep(stepName));
}
use of org.pentaho.di.trans.step.errorhandling.StreamInterface in project pentaho-kettle by pentaho.
the class AppendDialog method ok.
private void ok() {
if (Utils.isEmpty(wStepname.getText())) {
return;
}
List<StreamInterface> infoStreams = input.getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get(0);
StreamInterface tailStream = infoStreams.get(1);
headStream.setStepMeta(transMeta.findStep(wHeadHop.getText()));
tailStream.setStepMeta(transMeta.findStep(wTailHop.getText()));
// return value
stepname = wStepname.getText();
dispose();
}
Aggregations