Search in sources :

Example 21 with StreamInterface

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);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ArrayList(java.util.ArrayList) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 22 with StreamInterface

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);
    }
}
Also used : KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleException(org.pentaho.di.core.exception.KettleException) KettleXMLException(org.pentaho.di.core.exception.KettleXMLException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 23 with StreamInterface

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);
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 24 with StreamInterface

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));
}
Also used : TransHopMeta(org.pentaho.di.trans.TransHopMeta) RowGeneratorMeta(org.pentaho.di.trans.steps.rowgenerator.RowGeneratorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

Example 25 with StreamInterface

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();
}
Also used : StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface)

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