Search in sources :

Example 56 with InjectorMeta

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

the class ValueMapperIT method testValueMapper5.

/**
 * Test case for valuemapper step. Injector step to a valuemapper step to a dummy step. Rows go in and should be
 * mapped accordingly.
 *
 * This test will write the mappings in the same field. Using a non matching default.
 */
public void testValueMapper5() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("valuemappertest5");
    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 step
    // 
    String valueMapperName = "valuemapper step";
    ValueMapperMeta vm = new ValueMapperMeta();
    vm.setFieldToUse("field1");
    vm.setTargetField("");
    vm.setNonMatchDefault("default");
    vm.setSourceValue(new String[] { "abc", "ABC", "def", "ghij" });
    vm.setTargetValue(new String[] { "begin", "BEG_LONGER", "test", "" });
    String valueMapperPid = registry.getPluginId(StepPluginType.class, vm);
    StepMeta valueMapperStep = new StepMeta(valueMapperPid, valueMapperName, vm);
    transMeta.addStep(valueMapperStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, valueMapperStep);
    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(valueMapperStep, 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(valueMapperName, 0);
    RowStepCollector valueMapperRc = new RowStepCollector();
    si.addRowListener(valueMapperRc);
    si = trans.getStepInterface(dummyStepname2, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData5();
    checkRows(goldenImageRows, resultRows);
}
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 57 with InjectorMeta

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

the class ValueMapperIT method testValueMapper3.

/**
 * Test case for valuemapper step. Injector step to a valuemapper step to a dummy step. Rows go in and should be
 * mapped accordingly.
 *
 * This test will explicitly test the empty field processing.
 */
public void testValueMapper3() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("valuemappertest3");
    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 step
    // 
    String valueMapperName = "valuemapper step";
    ValueMapperMeta vm = new ValueMapperMeta();
    vm.setFieldToUse("field1");
    vm.setTargetField("");
    vm.setSourceValue(new String[] { "abc", "ABC", "def", "ghij", null });
    vm.setTargetValue(new String[] { "begin", "BEG_LONGER", "test", "", "emptyField" });
    String valueMapperPid = registry.getPluginId(StepPluginType.class, vm);
    StepMeta valueMapperStep = new StepMeta(valueMapperPid, valueMapperName, vm);
    transMeta.addStep(valueMapperStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, valueMapperStep);
    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(valueMapperStep, 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(valueMapperName, 0);
    RowStepCollector valueMapperRc = new RowStepCollector();
    si.addRowListener(valueMapperRc);
    si = trans.getStepInterface(dummyStepname2, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData3();
    checkRows(goldenImageRows, resultRows);
}
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 58 with InjectorMeta

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

the class ValueMapperIT method testValueMapper1.

/**
 * Test case for valuemapper step. Injector step to a valuemapper step to a dummy step. Rows go in and should be
 * mapped accordingly.
 *
 * This test will write the mappings in a new field.
 */
public void testValueMapper1() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("valuemappertest1");
    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 ValueMapper step
    // 
    String valueMapperName = "valuemapper step";
    ValueMapperMeta vm = new ValueMapperMeta();
    vm.setFieldToUse("field1");
    vm.setTargetField("new_field");
    vm.setSourceValue(new String[] { "abc", "ABC", "def", "ghij" });
    vm.setTargetValue(new String[] { "begin", "BEG_LONGER", "test", "" });
    String valueMapperPid = registry.getPluginId(StepPluginType.class, vm);
    StepMeta valueMapperStep = new StepMeta(valueMapperPid, valueMapperName, vm);
    transMeta.addStep(valueMapperStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, valueMapperStep);
    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(valueMapperStep, 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(valueMapperName, 0);
    RowStepCollector valueMapperRc = new RowStepCollector();
    si.addRowListener(valueMapperRc);
    si = trans.getStepInterface(dummyStepname2, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    // Compare the results
    List<RowMetaAndData> resultRows = dummyRc.getRowsWritten();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    checkRows(goldenImageRows, resultRows);
}
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)

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