Search in sources :

Example 61 with Trans

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

the class CheckSumTest method buildHexadecimalChecksumTrans.

private Trans buildHexadecimalChecksumTrans(int checkSumType, boolean compatibilityMode, boolean oldChecksumBehaviour) throws Exception {
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName(getClass().getName());
    // Create a CheckSum Step
    String checkSumStepname = "CheckSum";
    CheckSumMeta meta = new CheckSumMeta();
    // Set the compatibility mode and other required fields
    meta.setCompatibilityMode(compatibilityMode);
    meta.setResultFieldName("hex");
    meta.setCheckSumType(checkSumType);
    meta.setResultType(CheckSumMeta.result_TYPE_HEXADECIMAL);
    meta.setFieldName(new String[] { "test" });
    meta.setOldChecksumBehaviour(oldChecksumBehaviour);
    String checkSumPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, meta);
    StepMeta checkSumStep = new StepMeta(checkSumPluginPid, checkSumStepname, meta);
    transMeta.addStep(checkSumStep);
    // Create a Dummy step
    String dummyStepname = "Output";
    DummyTransMeta dummyMeta = new DummyTransMeta();
    String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
    StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
    transMeta.addStep(dummyStep);
    // Create a hop from CheckSum to Output
    TransHopMeta hop = new TransHopMeta(checkSumStep, dummyStep);
    transMeta.addTransHop(hop);
    return new Trans(transMeta);
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) 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 62 with Trans

use of org.pentaho.di.trans.Trans 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 63 with Trans

use of org.pentaho.di.trans.Trans 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 64 with Trans

use of org.pentaho.di.trans.Trans 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)

Example 65 with Trans

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

the class TableOutputIT method testTableOutputJIRA2733.

/**
 * Test case for commitSize see PDI2733 in JIRA.
 */
@SuppressWarnings("deprecation")
public void testTableOutputJIRA2733() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("table output JIRA2733 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_table3, createSourceRowMetaInterface1());
    // Add "ts" timestamp field to target_table with a default value of NOW()
    database.execStatement("ALTER TABLE " + target_table3 + " ADD COLUMN ts TIMESTAMP DEFAULT NOW() ");
    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_table3 + "]";
    TableOutputMeta tom = new TableOutputMeta();
    tom.setDatabaseMeta(transMeta.findDatabase("db"));
    tom.setTablename(target_table3);
    tom.setTruncateTable(true);
    tom.setUseBatchUpdate(true);
    String fromid = registry.getPluginId(StepPluginType.class, tom);
    StepMeta fromstep = new StepMeta(fromid, outputname, tom);
    fromstep.setDescription("write data to table [" + target_table3 + "] on database [" + dbInfo + "]");
    transMeta.addStep(fromstep);
    TransHopMeta hi = new TransHopMeta(injectorStep, fromstep);
    transMeta.addTransHop(hi);
    // With seven rows these are the number of commits that need to made
    // for "commitSize"s ranging between 0 and 8. (0=auto-commit=no commits)
    int[] goldRowCounts = { 1, 8, 4, 3, 2, 2, 2, 2, 1 };
    for (int commitSize = 0; commitSize <= 8; commitSize++) {
        tom.setCommitSize(commitSize);
        // 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();
        // Get the number of commits from the DB connection
        // in the table output step...
        // 
        TableOutputData data = (TableOutputData) trans.findDataInterface(outputname);
        int exp = goldRowCounts[commitSize];
        // remove 1 commit too many in the dispose method.
        // 
        int act = data.db.getNrExecutedCommits() - 1;
        assertEquals("Incorrect number of commits with commitSize=" + commitSize + Const.CR, exp, act);
    }
    dropTable(database, target_table3);
}
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

Trans (org.pentaho.di.trans.Trans)307 TransMeta (org.pentaho.di.trans.TransMeta)210 StepMeta (org.pentaho.di.trans.step.StepMeta)118 Test (org.junit.Test)95 StepInterface (org.pentaho.di.trans.step.StepInterface)92 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)84 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)81 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)73 RowStepCollector (org.pentaho.di.trans.RowStepCollector)71 KettleException (org.pentaho.di.core.exception.KettleException)65 RowProducer (org.pentaho.di.trans.RowProducer)58 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)54 TransPreviewProgressDialog (org.pentaho.di.ui.trans.dialog.TransPreviewProgressDialog)48 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)47 EnterTextDialog (org.pentaho.di.ui.core.dialog.EnterTextDialog)47 PreviewRowsDialog (org.pentaho.di.ui.core.dialog.PreviewRowsDialog)47 EnterNumberDialog (org.pentaho.di.ui.core.dialog.EnterNumberDialog)42 PrintWriter (java.io.PrintWriter)34 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)29