Search in sources :

Example 66 with TransHopMeta

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

the class DetectLastRowStepIT method detectLastRowStepTest.

/**
 * Test case Detect Last Row step. Nr of rows to test with as argument.
 *
 * @param nrRows
 *          Number of rows to test.
 *
 * @throws Exception
 *           upon any exception
 */
public void detectLastRowStepTest(int nrRows) throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("detectlastrowtest1");
    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 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 hi = new TransHopMeta(injectorStep, dummyStep1);
    transMeta.addTransHop(hi);
    // 
    // Create a detect last row step
    // 
    String delectLastRowStepname = "detect last row step";
    DetectLastRowMeta dlrm = new DetectLastRowMeta();
    dlrm.setResultFieldName("result");
    String detectLastRowStepPid = registry.getPluginId(StepPluginType.class, dlrm);
    StepMeta detectLastRowStep = new StepMeta(detectLastRowStepPid, delectLastRowStepname, dlrm);
    transMeta.addStep(detectLastRowStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, detectLastRowStep);
    transMeta.addTransHop(hi2);
    // 
    // Create a dummy step 2
    // 
    String dummyStepname2 = "dummy step 2";
    DummyTransMeta dm2 = new DummyTransMeta();
    String dummyPid2 = registry.getPluginId(StepPluginType.class, dm2);
    StepMeta dummyStep2 = new StepMeta(dummyPid2, dummyStepname2, dm2);
    transMeta.addStep(dummyStep2);
    TransHopMeta hi3 = new TransHopMeta(detectLastRowStep, dummyStep2);
    transMeta.addTransHop(hi3);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si = trans.getStepInterface(dummyStepname1, 0);
    RowStepCollector dummyRc1 = new RowStepCollector();
    si.addRowListener(dummyRc1);
    si = trans.getStepInterface(delectLastRowStepname, 0);
    RowStepCollector detectLastRc = new RowStepCollector();
    si.addRowListener(detectLastRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData(3);
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> resultRows1 = dummyRc1.getRowsRead();
    checkRows(resultRows1, inputList);
    List<RowMetaAndData> goldRows = createResultData(3);
    List<RowMetaAndData> resultRows2 = detectLastRc.getRowsWritten();
    checkRows(resultRows2, goldRows);
}
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) 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)

Example 67 with TransHopMeta

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

the class ExecSQLRowIT method testExecSQLRow1.

/**
 * Basic Test case for Exec SQL Row. This tests a commit size of zero (i.e. autocommit)
 */
@Test
public void testExecSQLRow1() 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"));
    // use Autocommit
    execsqlmeta.setCommitSize(0);
    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 68 with TransHopMeta

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

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

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

the class Spoon method doubleClickedInTree.

/**
 * Reaction to double click
 */
private void doubleClickedInTree(Tree tree, boolean shift) {
    TreeSelection[] objects = getTreeObjects(tree);
    if (objects.length != 1) {
        // not yet supported, we can do this later when the OSX bug
        return;
    // goes away
    }
    TreeSelection object = objects[0];
    final Object selection = object.getSelection();
    final Object parent = object.getParent();
    if (selection instanceof Class<?>) {
        if (selection.equals(TransMeta.class)) {
            newTransFile();
        }
        if (selection.equals(JobMeta.class)) {
            newJobFile();
        }
        if (selection.equals(TransHopMeta.class)) {
            newHop((TransMeta) parent);
        }
        if (selection.equals(DatabaseMeta.class)) {
            delegates.db.newConnection();
        }
        if (selection.equals(PartitionSchema.class)) {
            newPartitioningSchema((TransMeta) parent);
        }
        if (selection.equals(ClusterSchema.class)) {
            newClusteringSchema((TransMeta) parent);
        }
        if (selection.equals(SlaveServer.class)) {
            newSlaveServer((HasSlaveServersInterface) parent);
        }
    } else {
        if (selection instanceof TransMeta) {
            TransGraph.editProperties((TransMeta) selection, this, rep, true);
        }
        if (selection instanceof JobMeta) {
            JobGraph.editProperties((JobMeta) selection, this, rep, true);
        }
        if (selection instanceof PluginInterface) {
            PluginInterface plugin = (PluginInterface) selection;
            if (plugin.getPluginType().equals(StepPluginType.class)) {
                TransGraph transGraph = getActiveTransGraph();
                if (transGraph != null) {
                    transGraph.addStepToChain(plugin, shift);
                }
            }
            if (plugin.getPluginType().equals(JobEntryPluginType.class)) {
                JobGraph jobGraph = getActiveJobGraph();
                if (jobGraph != null) {
                    jobGraph.addJobEntryToChain(object.getItemText(), shift);
                }
            }
        }
        if (selection instanceof DatabaseMeta) {
            DatabaseMeta database = (DatabaseMeta) selection;
            delegates.db.editConnection(database);
        }
        if (selection instanceof StepMeta) {
            StepMeta step = (StepMeta) selection;
            delegates.steps.editStep((TransMeta) parent, step);
            sharedObjectSyncUtil.synchronizeSteps(step);
        }
        if (selection instanceof JobEntryCopy) {
            editJobEntry((JobMeta) parent, (JobEntryCopy) selection);
        }
        if (selection instanceof TransHopMeta) {
            editHop((TransMeta) parent, (TransHopMeta) selection);
        }
        if (selection instanceof PartitionSchema) {
            editPartitionSchema((TransMeta) parent, (PartitionSchema) selection);
        }
        if (selection instanceof ClusterSchema) {
            delegates.clusters.editClusterSchema((TransMeta) parent, (ClusterSchema) selection);
        }
        if (selection instanceof SlaveServer) {
            editSlaveServer((SlaveServer) selection);
        }
        editSelectionTreeExtension(selection);
    }
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) PartitionSchema(org.pentaho.di.partition.PartitionSchema) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) TransMeta(org.pentaho.di.trans.TransMeta) TransGraph(org.pentaho.di.ui.spoon.trans.TransGraph) SlaveServer(org.pentaho.di.cluster.SlaveServer) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StepMeta(org.pentaho.di.trans.step.StepMeta) JobGraph(org.pentaho.di.ui.spoon.job.JobGraph) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) RepositoryObject(org.pentaho.di.repository.RepositoryObject) SimpleLoggingObject(org.pentaho.di.core.logging.SimpleLoggingObject) FileObject(org.apache.commons.vfs2.FileObject) TransHopMeta(org.pentaho.di.trans.TransHopMeta) ClusterSchema(org.pentaho.di.cluster.ClusterSchema)

Aggregations

TransHopMeta (org.pentaho.di.trans.TransHopMeta)153 StepMeta (org.pentaho.di.trans.step.StepMeta)127 TransMeta (org.pentaho.di.trans.TransMeta)114 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)80 Trans (org.pentaho.di.trans.Trans)78 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)71 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)71 StepInterface (org.pentaho.di.trans.step.StepInterface)70 RowStepCollector (org.pentaho.di.trans.RowStepCollector)66 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)63 RowProducer (org.pentaho.di.trans.RowProducer)49 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)49 Test (org.junit.Test)35 KettleException (org.pentaho.di.core.exception.KettleException)28 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)25 Point (org.pentaho.di.core.gui.Point)21 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)19 NotePadMeta (org.pentaho.di.core.NotePadMeta)15 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)14 File (java.io.File)12