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);
}
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);
}
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);
}
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());
}
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);
}
}
Aggregations