Search in sources :

Example 56 with StepInterface

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

the class MappingIT method runTransWhenMappingsIsFollowedByCopiedStep.

/**
 * This method runs transformations related to PDI-13545.<br/> The scenario is the following: there are two step
 * generating data, the latter of which is a Mapping step. They are followed with a Join Rows step, that has two
 * copies. The last in a row is a Dummy step, named "Last". Since both generating steps output 3 rows ([10, 20, 30]
 * and [1, 2, 3] respectively), the last step must obtain 3*3=9 rows.
 *
 * @param transPath a path to transformation file
 * @throws Exception
 */
private void runTransWhenMappingsIsFollowedByCopiedStep(String transPath) throws Exception {
    KettleEnvironment.init();
    TransMeta transMeta = new TransMeta(transPath);
    transMeta.setTransformationType(TransMeta.TransformationType.Normal);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    trans.startThreads();
    trans.waitUntilFinished();
    assertEquals(0, trans.getErrors());
    List<StepInterface> list = trans.findBaseSteps("Last");
    assertEquals(1, list.size());
    assertEquals(9, list.get(0).getLinesRead());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) TransMeta(org.pentaho.di.trans.TransMeta) Trans(org.pentaho.di.trans.Trans)

Example 57 with StepInterface

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

the class MappingIT method testInfoStreams_single.

/**
 * Tests that info steps are correctly identified via StepMetaInterface.getStepIOMeta()
 */
public void testInfoStreams_single() throws Exception {
    KettleEnvironment.init();
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // Create a new transformation with a row generator that feeds a Mapping (Sub-Transformation) Step
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Mapping Info Test");
    StepMeta rowGenerator = buildRowGeneratorStep(registry, "Generate Rows");
    transMeta.addStep(rowGenerator);
    String mappingName = "mapping";
    MappingMeta mappingMeta = new MappingMeta();
    mappingMeta.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    mappingMeta.setFileName("test/org/pentaho/di/trans/steps/mapping/subtrans.ktr");
    String mappingInputStepName = "input";
    mappingMeta.setInputMappings(Collections.singletonList(createMappingDef(rowGenerator.getName(), mappingInputStepName, "string", "a")));
    String mappingPid = registry.getPluginId(StepPluginType.class, mappingMeta);
    StepMeta mapping = new StepMeta(mappingPid, mappingName, mappingMeta);
    transMeta.addStep(mapping);
    TransHopMeta hopGeneratorToMapping = new TransHopMeta(rowGenerator, mapping);
    transMeta.addTransHop(hopGeneratorToMapping);
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    // (Copied from TransMeta.loadXML())
    for (int i = 0; i < transMeta.nrSteps(); i++) {
        StepMeta stepMeta = transMeta.getStep(i);
        StepMetaInterface sii = stepMeta.getStepMetaInterface();
        if (sii != null) {
            sii.searchInfoAndTargetSteps(transMeta.getSteps());
        }
    }
    // Verify the transformation was configured properly
    assertEquals("Transformation not initialized properly", 2, transMeta.nrSteps());
    StepMeta meta = transMeta.getStep(1);
    assertTrue("Transformation not initialized properly", meta.getStepMetaInterface() instanceof MappingMeta);
    MappingMeta loadedMappingMeta = (MappingMeta) meta.getStepMetaInterface();
    assertEquals("Expected a single input mapping definition", 1, loadedMappingMeta.getInputMappings().size());
    StepIOMetaInterface ioMeta = loadedMappingMeta.getStepIOMeta();
    assertEquals("Expected a single Info Stream", 1, ioMeta.getInfoStreams().size());
    assertEquals("Expected a single Info Step", 1, loadedMappingMeta.getInfoSteps().length);
    // Verify the transformation can be executed
    StepInterface si = trans.getStepInterface(mappingName, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    trans.startThreads();
    trans.waitUntilFinished();
    assertEquals(1, rc.getRowsRead().size());
    assertEquals(1, rc.getRowsWritten().size());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans)

Example 58 with StepInterface

use of org.pentaho.di.trans.step.StepInterface 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 59 with StepInterface

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

the class RestInputIT method createAndTestTrans.

protected Trans createAndTestTrans(PluginRegistry registry, TransMeta transMeta, StepMeta inputStep, RowStepCollector rowStepCollector, String name, int limit) throws KettleException {
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname, dm1);
    transMeta.addStep(dummyStep1);
    TransHopMeta hi3 = new TransHopMeta(inputStep, dummyStep1);
    transMeta.addTransHop(hi3);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    si.addRowListener(rowStepCollector);
    RowProducer rp = trans.addRowProducer(inputStep.getName(), 0);
    RowMeta rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("pageSize"));
    rowMeta.addValueMeta(new ValueMetaString("name"));
    rp.putRow(rowMeta, new Object[] { Integer.valueOf(limit), name });
    rp.finished();
    return trans;
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowProducer(org.pentaho.di.trans.RowProducer) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 60 with StepInterface

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

the class RowGeneratorIT method testRowGenerator.

/**
 * Test case for Row Generator step.
 */
public void testRowGenerator() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("row generatortest");
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create a row generator step...
    // 
    String rowGeneratorStepname = "row generator step";
    RowGeneratorMeta rm = new RowGeneratorMeta();
    // Set the information of the row generator.
    String rowGeneratorPid = registry.getPluginId(StepPluginType.class, rm);
    StepMeta rowGeneratorStep = new StepMeta(rowGeneratorPid, rowGeneratorStepname, rm);
    transMeta.addStep(rowGeneratorStep);
    // 
    // Do the following specs 3 times.
    // 
    String[] fieldName = { "string", "boolean", "integer", "timestamp" };
    String[] type = { "String", "Boolean", "Integer", "Timestamp" };
    String[] value = { "string_value", "true", "20", "1970-01-01 00:00:00.000" };
    String[] fieldFormat = { "", "", "", "" };
    String[] group = { "", "", "", "" };
    String[] decimal = { "", "", "", "" };
    String[] currency = { "", "", "", "" };
    int[] intDummies = { -1, -1, -1, -1 };
    boolean[] setEmptystring = { false, false, false, false };
    rm.setDefault();
    rm.setFieldName(fieldName);
    rm.setFieldType(type);
    rm.setValue(value);
    rm.setFieldLength(intDummies);
    rm.setFieldPrecision(intDummies);
    rm.setRowLimit("3");
    rm.setFieldFormat(fieldFormat);
    rm.setGroup(group);
    rm.setDecimal(decimal);
    rm.setCurrency(currency);
    rm.setEmptyString(setEmptystring);
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    TransHopMeta hi = new TransHopMeta(rowGeneratorStep, dummyStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    trans.startThreads();
    trans.waitUntilFinished();
    List<RowMetaAndData> checkList = createData();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    checkRows(resultRows, checkList);
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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)

Aggregations

StepInterface (org.pentaho.di.trans.step.StepInterface)150 Trans (org.pentaho.di.trans.Trans)88 StepMeta (org.pentaho.di.trans.step.StepMeta)88 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)75 TransMeta (org.pentaho.di.trans.TransMeta)73 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)69 RowStepCollector (org.pentaho.di.trans.RowStepCollector)68 TransHopMeta (org.pentaho.di.trans.TransHopMeta)67 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)66 RowProducer (org.pentaho.di.trans.RowProducer)57 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)50 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)49 Test (org.junit.Test)37 KettleException (org.pentaho.di.core.exception.KettleException)28 StepMetaDataCombi (org.pentaho.di.trans.step.StepMetaDataCombi)19 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)17 ArrayList (java.util.ArrayList)15 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)14 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)14 RowSet (org.pentaho.di.core.RowSet)13