Search in sources :

Example 21 with StepInterface

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

the class TransPartitioningTest method testManyToManyCopies.

/**
 * This checks transformation initialization when using many to many copies.
 *
 * @throws KettleException
 */
@Test
public void testManyToManyCopies() throws KettleException {
    prepareStepMetas_x2_x2();
    trans.prepareExecution(new String[] {});
    List<RowSet> rowsets = trans.getRowsets();
    assertTrue(!rowsets.isEmpty());
    assertEquals("We have 2 rowsets finally", 2, rowsets.size());
    assertEquals("We have 4 steps: 2 copies of producer and 2 copies of consumer", 4, trans.getSteps().size());
    // Ok, examine initialized steps now.
    StepInterface stepOne0 = getStepByName(S10);
    assertTrue("1 step have no input row sets", stepOne0.getInputRowSets().isEmpty());
    assertEquals("1 step have 1 output rowsets", 1, stepOne0.getOutputRowSets().size());
    StepInterface stepOne1 = getStepByName(S11);
    assertTrue("1 step have no input row sets", stepOne1.getInputRowSets().isEmpty());
    assertEquals("1 step have 1 output rowsets", 1, stepOne1.getOutputRowSets().size());
    StepInterface stepTwo0 = getStepByName(S20);
    Assert.assertEquals("2.0 step have 1 input row sets", 1, stepTwo0.getInputRowSets().size());
    Assert.assertTrue("2.0 step have no output row sets", stepTwo0.getOutputRowSets().isEmpty());
    StepInterface stepTwo1 = getStepByName(S21);
    Assert.assertEquals("2.1 step have 1 input row sets", 1, stepTwo1.getInputRowSets().size());
    Assert.assertTrue("2.1 step have no output row sets", stepTwo1.getOutputRowSets().isEmpty());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowSet(org.pentaho.di.core.RowSet) Test(org.junit.Test)

Example 22 with StepInterface

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

the class TransPartitioningTest method testOneToManyCopies.

/**
 * This checks transformation initialization when using one to many copies
 *
 * @throws KettleException
 */
@Test
public void testOneToManyCopies() throws KettleException {
    prepareStepMetas_1_x2();
    trans.prepareExecution(new String[] {});
    List<RowSet> rowsets = trans.getRowsets();
    assertTrue(!rowsets.isEmpty());
    assertEquals("We have 2 rowsets finally", 2, rowsets.size());
    assertEquals("We have 3 steps: one producer and 2 copies of consumer", 3, trans.getSteps().size());
    // Ok, examine initialized steps now.
    StepInterface stepOne = getStepByName(S10);
    assertTrue("1 step have no input row sets", stepOne.getInputRowSets().isEmpty());
    assertEquals("1 step have 2 output rowsets", 2, stepOne.getOutputRowSets().size());
    StepInterface stepTwo0 = getStepByName(S20);
    Assert.assertEquals("2.0 step have 12 input row sets", 1, stepTwo0.getInputRowSets().size());
    Assert.assertTrue("2.0 step have no output row sets", stepTwo0.getOutputRowSets().isEmpty());
    StepInterface stepTwo1 = getStepByName(S21);
    Assert.assertEquals("2.1 step have 1 input row sets", 1, stepTwo1.getInputRowSets().size());
    Assert.assertTrue("2.1 step have no output row sets", stepTwo1.getOutputRowSets().isEmpty());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowSet(org.pentaho.di.core.RowSet) Test(org.junit.Test)

Example 23 with StepInterface

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

the class CheckSumTest method executeHexTest.

/**
 * Create, execute, and return the row listener attached to the output step with complete results from the execution.
 *
 * @param checkSumType
 *          Type of checksum to use (the array index of {@link CheckSumMeta#checksumtypeCodes})
 * @param compatibilityMode
 *          Use compatibility mode for CheckSum
 * @param input
 *          String to calculate checksum for
 * @param meta
 *          meta to be used
 * @return RowListener with results.
 */
private MockRowListener executeHexTest(int checkSumType, boolean compatibilityMode, Object input, ValueMetaInterface meta, boolean oldChecksumBehaviour) throws Exception {
    Trans trans = buildHexadecimalChecksumTrans(checkSumType, compatibilityMode, oldChecksumBehaviour);
    trans.prepareExecution(null);
    StepInterface output = trans.getRunThread("Output", 0);
    MockRowListener listener = new MockRowListener();
    output.addRowListener(listener);
    RowProducer rp = trans.addRowProducer("CheckSum", 0);
    RowMeta inputRowMeta = createStringRowMeta(meta);
    ((BaseStep) trans.getRunThread("CheckSum", 0)).setInputRowMeta(inputRowMeta);
    trans.startThreads();
    rp.putRow(inputRowMeta, new Object[] { input });
    rp.finished();
    trans.waitUntilFinished();
    trans.stopAll();
    trans.cleanup();
    return listener;
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowProducer(org.pentaho.di.trans.RowProducer) BaseStep(org.pentaho.di.trans.step.BaseStep) RowMeta(org.pentaho.di.core.row.RowMeta) Trans(org.pentaho.di.trans.Trans)

Example 24 with StepInterface

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

the class TableInputIT method testTableInputWithParam.

/**
 * Test case for table input which is taking its input from a hop. This is a regression test case for JIRA PDI-588.
 *
 * The query in the table input step has one '?' and this parameter is filled by values read from an input hop.
 */
public void testTableInputWithParam() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("transname");
    // Add the database connections
    for (int i = 0; i < databasesXML.length; i++) {
        DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
        transMeta.addDatabase(databaseMeta);
    }
    DatabaseMeta dbInfo = transMeta.findDatabase("db");
    // Execute our setup SQLs in the database.
    Database database = new Database(transMeta, dbInfo);
    database.connect();
    createTables(database);
    createData(database);
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // create the source step...
    // 
    String fromstepname = "read from [" + source_table + "]";
    TableInputMeta tii = new TableInputMeta();
    tii.setDatabaseMeta(transMeta.findDatabase("db"));
    tii.setLookupFromStep(injectorStep);
    tii.setExecuteEachInputRow(true);
    String selectSQL = "SELECT " + Const.CR;
    selectSQL += "ID, CODE ";
    selectSQL += "FROM " + source_table + " WHERE CODE = ? ORDER BY ID, CODE;";
    tii.setSQL(selectSQL);
    String fromstepid = registry.getPluginId(StepPluginType.class, tii);
    StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
    fromstep.setDescription("Reads information from table [" + source_table + "] on database [" + dbInfo + "]");
    transMeta.addStep(fromstep);
    TransHopMeta hi = new TransHopMeta(injectorStep, fromstep);
    transMeta.addTransHop(hi);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(fromstepname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createDataRows();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    List<RowMetaAndData> goldRows = createResultDataRows();
    checkRows(goldRows, resultRows);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Database(org.pentaho.di.core.database.Database) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans)

Example 25 with StepInterface

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

the class TableOutputIT method testTableOutputNormal.

/**
 * Test case for normal table output case.
 */
@SuppressWarnings("deprecation")
public void testTableOutputNormal() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("table output normal test");
    // Add the database connections
    for (int i = 0; i < databasesXML.length; i++) {
        DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
        transMeta.addDatabase(databaseMeta);
    }
    DatabaseMeta dbInfo = transMeta.findDatabase("db");
    // Execute our setup SQLs in the database.
    Database database = new Database(transMeta, dbInfo);
    database.connect();
    createTable(database, target_table, createSourceRowMetaInterface1());
    PluginRegistry registry = PluginRegistry.getInstance();
    // 
    // create an injector step...
    // 
    String injectorStepname = "injector step";
    InjectorMeta im = new InjectorMeta();
    // Set the information of the injector.
    String injectorPid = registry.getPluginId(StepPluginType.class, im);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
    transMeta.addStep(injectorStep);
    // 
    // create the source step...
    // 
    String outputname = "output to [" + target_table + "]";
    TableOutputMeta tom = new TableOutputMeta();
    tom.setDatabaseMeta(transMeta.findDatabase("db"));
    tom.setTablename(target_table);
    String fromid = registry.getPluginId(StepPluginType.class, tom);
    StepMeta fromstep = new StepMeta(fromid, outputname, tom);
    fromstep.setDescription("write data to table [" + target_table + "] on database [" + dbInfo + "]");
    transMeta.addStep(fromstep);
    TransHopMeta hi = new TransHopMeta(injectorStep, fromstep);
    transMeta.addTransHop(hi);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(outputname, 0);
    RowStepCollector rc = new RowStepCollector();
    si.addRowListener(rc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createNormalDataRows();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> resultRows = rc.getRowsWritten();
    List<RowMetaAndData> goldRows = createNormalDataRows();
    checkRows(goldRows, resultRows);
    checkResultsNormal(database);
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) RowStepCollector(org.pentaho.di.trans.RowStepCollector) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) StepInterface(org.pentaho.di.trans.step.StepInterface) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) Database(org.pentaho.di.core.database.Database) 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