Search in sources :

Example 31 with InjectorMeta

use of org.pentaho.di.trans.steps.injector.InjectorMeta in project pentaho-kettle by pentaho.

the class ExecSQLRowIT method testExecSQLRow3.

/**
 * Basic Test case for Exec SQL Row. This tests a commit size of two (i.e. not autocommit and not the input row size)
 */
@Test
public void testExecSQLRow3() 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");
    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 Exec SQL Row step...
    // 
    String stepName = "delete from [" + execsqlrow_testtable + "]";
    ExecSQLRowMeta execsqlmeta = new ExecSQLRowMeta();
    execsqlmeta.setDatabaseMeta(transMeta.findDatabase("db"));
    execsqlmeta.setCommitSize(2);
    execsqlmeta.setSqlFieldName("SQL");
    String execSqlRowId = registry.getPluginId(StepPluginType.class, execsqlmeta);
    StepMeta execSqlRowStep = new StepMeta(execSqlRowId, stepName, execsqlmeta);
    execSqlRowStep.setDescription("Deletes information from table [" + execsqlrow_testtable + "] on database [" + dbInfo + "]");
    transMeta.addStep(execSqlRowStep);
    TransHopMeta hi = new TransHopMeta(injectorStep, execSqlRowStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(stepName, 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) 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) TransHopMeta(org.pentaho.di.trans.TransHopMeta) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 32 with InjectorMeta

use of org.pentaho.di.trans.steps.injector.InjectorMeta in project pentaho-kettle by pentaho.

the class FilterRowsIT method testFilterConditionRefersToNonExistingFields.

@Test
public void testFilterConditionRefersToNonExistingFields() throws Exception {
    KettleEnvironment.init();
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("filterrowstest");
    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 a filter rows step
    String filterStepName = "filter rows step";
    FilterRowsMeta frm = new FilterRowsMeta();
    Condition condition = new Condition();
    String nonExistingFieldName = "non-existing-field";
    condition.setLeftValuename(nonExistingFieldName);
    // IS NOT
    condition.setFunction(8);
    condition.setRightValuename(null);
    condition.setOperator(0);
    frm.setCondition(condition);
    String filterRowsStepPid = registry.getPluginId(StepPluginType.class, frm);
    StepMeta filterRowsStep = new StepMeta(filterRowsStepPid, filterStepName, frm);
    transMeta.addStep(filterRowsStep);
    TransHopMeta hi = new TransHopMeta(injectorStep, filterRowsStep);
    transMeta.addTransHop(hi);
    // Now execute the transformation
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    // add rows
    List<RowMetaAndData> inputList = createIntegerData();
    for (RowMetaAndData rm : inputList) {
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.startThreads();
    trans.waitUntilFinished();
    // expect errors
    assertEquals(1, trans.getErrors());
}
Also used : Condition(org.pentaho.di.core.Condition) RowProducer(org.pentaho.di.trans.RowProducer) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) 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) Test(org.junit.Test)

Example 33 with InjectorMeta

use of org.pentaho.di.trans.steps.injector.InjectorMeta in project pdi-dataservice-server-plugin by pentaho.

the class SqlTransGenerator method generateInjectorStep.

private StepMeta generateInjectorStep() {
    InjectorMeta meta = new InjectorMeta();
    meta.allocate(serviceFields.size());
    for (int i = 0; i < serviceFields.size(); i++) {
        ValueMetaInterface valueMeta = serviceFields.getValueMeta(i);
        meta.getFieldname()[i] = valueMeta.getName();
        meta.getType()[i] = valueMeta.getType();
        meta.getLength()[i] = valueMeta.getLength();
        meta.getPrecision()[i] = valueMeta.getPrecision();
    }
    StepMeta stepMeta = new StepMeta("Injector", meta);
    stepMeta.setLocation(xLocation, 50);
    xLocation += 100;
    stepMeta.setDraw(true);
    return stepMeta;
}
Also used : InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 34 with InjectorMeta

use of org.pentaho.di.trans.steps.injector.InjectorMeta in project pentaho-kettle by pentaho.

the class SynchronizeAfterMergeIT method setUp.

@Before
public void setUp() throws KettleDatabaseException, SQLException {
    connection = DriverManager.getConnection("jdbc:h2:mem:PERSON;");
    connection.setAutoCommit(false);
    PreparedStatement stmt = connection.prepareStatement("CREATE TABLE PERSON (ID INT PRIMARY KEY, personName VARCHAR(64) )");
    stmt.execute();
    stmt.close();
    stmt = connection.prepareStatement("INSERT INTO PERSON (ID, personName) VALUES (?, ?)");
    for (int i = 0; i < ROW_FOR_UPDATE + ROW_FOR_DELETE; i++) {
        stmt.setInt(1, i);
        stmt.setString(2, "personName" + i);
        stmt.addBatch();
    }
    stmt.executeBatch();
    stmt.close();
    connection.commit();
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    transMeta = new TransMeta();
    transMeta.setName("SynchronizeAfterMerge");
    InjectorMeta injectorMeta = new InjectorMeta();
    String injectorPid = pluginRegistry.getPluginId(StepPluginType.class, injectorMeta);
    StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, injectorMeta);
    transMeta.addStep(injectorStep);
    DatabaseMeta dbMeta = spy(new DatabaseMeta());
    dbMeta.setDatabaseType("H2");
    when(dbMeta.getURL()).thenReturn("jdbc:h2:mem:PERSON;");
    when(dbMeta.supportsErrorHandlingOnBatchUpdates()).thenReturn(false);
    SynchronizeAfterMergeMeta synchronizeAfterMergeMeta = new SynchronizeAfterMergeMeta();
    // set commit size
    synchronizeAfterMergeMeta.setCommitSize(COMMIT_SIZE);
    synchronizeAfterMergeMeta.setDatabaseMeta(dbMeta);
    synchronizeAfterMergeMeta.setKeyCondition(new String[] { "=" });
    synchronizeAfterMergeMeta.setKeyLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setKeyStream(new String[] { "personName" });
    synchronizeAfterMergeMeta.setKeyStream2(new String[] { null });
    synchronizeAfterMergeMeta.setUpdate(new Boolean[] { Boolean.TRUE });
    synchronizeAfterMergeMeta.setOperationOrderField("flag");
    synchronizeAfterMergeMeta.setOrderDelete(DELETE_FLAG);
    synchronizeAfterMergeMeta.setOrderInsert(INSERT_FLAG);
    synchronizeAfterMergeMeta.setOrderUpdate(UPDATE_FLAG);
    synchronizeAfterMergeMeta.setPerformLookup(true);
    synchronizeAfterMergeMeta.setTableName("PERSON");
    synchronizeAfterMergeMeta.settablenameInField(false);
    synchronizeAfterMergeMeta.settablenameField(null);
    synchronizeAfterMergeMeta.setUseBatchUpdate(true);
    synchronizeAfterMergeMeta.setUpdateLookup(new String[] { "ID" });
    synchronizeAfterMergeMeta.setUpdateStream(new String[] { "personName" });
    String synchronizeAfterMergePid = pluginRegistry.getPluginId(StepPluginType.class, synchronizeAfterMergeStepname);
    StepMeta synchronizeAfterMerge = new StepMeta(synchronizeAfterMergePid, synchronizeAfterMergeStepname, synchronizeAfterMergeMeta);
    transMeta.addStep(synchronizeAfterMerge);
    String dummyResultStepName = "dummyResultStepName";
    DummyTransMeta dummyResultTransMeta = new DummyTransMeta();
    String dummyResultPid = pluginRegistry.getPluginId(StepPluginType.class, dummyResultTransMeta);
    StepMeta dummyResultStep = new StepMeta(dummyResultPid, dummyResultStepName, dummyResultTransMeta);
    transMeta.addStep(dummyResultStep);
    String dummyErrorStepName = "dummyErrorStepName";
    DummyTransMeta dummyErrorTransMeta = new DummyTransMeta();
    String dummyErrorPid = pluginRegistry.getPluginId(StepPluginType.class, dummyErrorTransMeta);
    StepMeta dummyErrorStep = new StepMeta(dummyErrorPid, dummyErrorStepName, dummyErrorTransMeta);
    transMeta.addStep(dummyErrorStep);
    StepErrorMeta stepErrorMeta = new StepErrorMeta(transMeta, synchronizeAfterMerge, dummyErrorStep);
    stepErrorMeta.setEnabled(true);
    synchronizeAfterMerge.setStepErrorMeta(stepErrorMeta);
    TransHopMeta injSynch = new TransHopMeta(injectorStep, synchronizeAfterMerge);
    transMeta.addTransHop(injSynch);
    TransHopMeta synchDummyResult = new TransHopMeta(synchronizeAfterMerge, dummyResultStep);
    transMeta.addTransHop(synchDummyResult);
    TransHopMeta synchDummyError = new TransHopMeta(synchronizeAfterMerge, dummyErrorStep);
    transMeta.addTransHop(synchDummyError);
}
Also used : PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepErrorMeta(org.pentaho.di.trans.step.StepErrorMeta) PreparedStatement(java.sql.PreparedStatement) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) TransHopMeta(org.pentaho.di.trans.TransHopMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Before(org.junit.Before)

Example 35 with InjectorMeta

use of org.pentaho.di.trans.steps.injector.InjectorMeta in project pentaho-kettle by pentaho.

the class TransTestFactory method getInjectorStepMeta.

static StepMeta getInjectorStepMeta(RowMetaInterface outputRowMeta) {
    InjectorMeta zeroMeta = new InjectorMeta();
    // Sets output fields for cases when no rows are sent to the test step, but metadata is still needed
    if (outputRowMeta != null && outputRowMeta.size() > 0) {
        String[] fieldName = new String[outputRowMeta.size()];
        int[] fieldLength = new int[outputRowMeta.size()];
        int[] fieldPrecision = new int[outputRowMeta.size()];
        int[] fieldType = new int[outputRowMeta.size()];
        for (int i = 0; i < outputRowMeta.size(); i++) {
            ValueMetaInterface field = outputRowMeta.getValueMeta(i);
            fieldName[i] = field.getName();
            fieldLength[i] = field.getLength();
            fieldPrecision[i] = field.getPrecision();
            fieldType[i] = field.getType();
        }
        zeroMeta.setFieldname(fieldName);
        zeroMeta.setLength(fieldLength);
        zeroMeta.setPrecision(fieldPrecision);
        zeroMeta.setType(fieldType);
    }
    StepMeta zero = new StepMeta(registry.getPluginId(StepPluginType.class, zeroMeta), INJECTOR_STEPNAME, zeroMeta);
    zero.setLocation(50, 50);
    zero.setDraw(true);
    return zero;
}
Also used : StepPluginType(org.pentaho.di.core.plugins.StepPluginType) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Aggregations

StepMeta (org.pentaho.di.trans.step.StepMeta)58 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)58 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)52 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)49 TransHopMeta (org.pentaho.di.trans.TransHopMeta)49 TransMeta (org.pentaho.di.trans.TransMeta)49 StepInterface (org.pentaho.di.trans.step.StepInterface)49 Trans (org.pentaho.di.trans.Trans)47 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)46 RowStepCollector (org.pentaho.di.trans.RowStepCollector)46 RowProducer (org.pentaho.di.trans.RowProducer)45 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)37 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)15 Test (org.junit.Test)13 UniqueRowsMeta (org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta)7 Database (org.pentaho.di.core.database.Database)6 ArrayList (java.util.ArrayList)5 SortRowsMeta (org.pentaho.di.trans.steps.sort.SortRowsMeta)4 Before (org.junit.Before)3 KettleException (org.pentaho.di.core.exception.KettleException)2