Search in sources :

Example 71 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class StringCutIT method testStringCut1.

/**
 * This is a test for PDI-8042, where the first row of meta has no output field but the second does.
 */
@Test
public void testStringCut1() throws KettleException {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("stringcuttest1");
    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 String Cut step
    // 
    String stringcutStepname = "string cut step";
    StringCutMeta scm = new StringCutMeta();
    scm.setFieldInStream(new String[] { "field1", "field2" });
    scm.setFieldOutStream(new String[] { null, "outf3" });
    scm.setCutFrom(new String[] { null, "1" });
    scm.setCutTo(new String[] { null, "3" });
    String stringCutStepPid = registry.getPluginId(StepPluginType.class, scm);
    StepMeta stringCutStep = new StepMeta(stringCutStepPid, stringcutStepname, scm);
    transMeta.addStep(stringCutStep);
    TransHopMeta hi2 = new TransHopMeta(dummyStep1, stringCutStep);
    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(stringCutStep, 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(stringcutStepname, 0);
    RowStepCollector stringCutRc = new RowStepCollector();
    si.addRowListener(stringCutRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData1();
    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 = createResultData1();
    List<RowMetaAndData> resultRows2 = stringCutRc.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) Test(org.junit.Test)

Example 72 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class JavaScriptSpecialIT method disabledTestJavaInterface.

/**
 * Test case for JavaScript/Java/JavaScript interfacing.
 */
public void disabledTestJavaInterface() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("test javascript interface");
    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 javascript step
    // 
    String javaScriptStepname = "javascript step";
    ScriptValuesMetaMod svm = new ScriptValuesMetaMod();
    // process 3 rows and skip the rest.
    ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script1", "java;\n\n" + "var obj     = new Packages.org.pentaho.di.trans.steps.scriptvalues_mod.JavaScriptTest();\n" + "var long1   = obj.add1ToLong(getInputRowMeta().getInteger(row, 0));\n" + "var number1 = obj.add1ToNumber(getInputRowMeta().getNumber(row, 1));\n" + "var string1 = obj.add1ToString(getInputRowMeta().getString(row, 2));\n" + "var long2   = Packages.org.pentaho.di.trans.steps.scriptvalues_mod." + "JavaScriptTest.add1ToLongStatic(getInputRowMeta().getInteger(row, 0));\n" + "var number2 = Packages.org.pentaho.di.trans.steps.scriptvalues_mod." + "JavaScriptTest.add1ToNumberStatic(getInputRowMeta().getNumber(row, 1));\n" + "var string2 = Packages.org.pentaho.di.trans.steps.scriptvalues_mod." + "JavaScriptTest.add1ToStringStatic(getInputRowMeta().getString(row, 2));\n") };
    svm.setJSScripts(js);
    svm.setFieldname(new String[] { "long1", "number1", "string1", "long2", "number2", "string2" });
    svm.setRename(new String[] { "long1", "number1", "string1", "long2", "number2", "string2" });
    svm.setType(new int[] { ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_NUMBER, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_INTEGER, ValueMetaInterface.TYPE_NUMBER, ValueMetaInterface.TYPE_STRING });
    svm.setLength(new int[] { -1, -1, -1, -1, -1, -1, -1 });
    svm.setPrecision(new int[] { -1, -1, -1, -1, -1, -1, -1 });
    svm.setReplace(new boolean[] { false, false, false, false, false, false });
    svm.setCompatible(false);
    String javaScriptStepPid = registry.getPluginId(StepPluginType.class, svm);
    StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, svm);
    transMeta.addStep(javaScriptStep);
    TransHopMeta hi1 = new TransHopMeta(injectorStep, javaScriptStep);
    transMeta.addTransHop(hi1);
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
    transMeta.addTransHop(hi2);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si;
    si = trans.getStepInterface(javaScriptStepname, 0);
    RowStepCollector javaScriptRc = new RowStepCollector();
    si.addRowListener(javaScriptRc);
    si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData3();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> goldenImageRows = createResultData3();
    List<RowMetaAndData> resultRows1 = javaScriptRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
    List<RowMetaAndData> resultRows2 = dummyRc.getRowsRead();
    checkRows(resultRows2, goldenImageRows);
}
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 73 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class JavaScriptStringIT method testStringsTrim.

/**
 * Test case for javascript functionality: ltrim(), rtrim(), trim().
 */
public void testStringsTrim() throws Exception {
    KettleEnvironment.init();
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("test javascript trim");
    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 javascript step
    // 
    String javaScriptStepname = "javascript step";
    ScriptValuesMetaMod svm = new ScriptValuesMetaMod();
    ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var original = 'b' + string.getString() + 'e';\n" + "var ltrimStr = 'b' + ltrim(string.getString()) + 'e';\n" + "var rtrimStr = 'b' + rtrim(string.getString()) + 'e';\n" + "var trimStr  = 'b' + trim(string.getString()) + 'e';\n") };
    svm.setJSScripts(js);
    svm.setFieldname(new String[] { "original", "ltrimStr", "rtrimStr", "trimStr" });
    svm.setRename(new String[] { "", "", "", "" });
    svm.setType(new int[] { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING });
    svm.setLength(new int[] { -1, -1, -1, -1 });
    svm.setPrecision(new int[] { -1, -1, -1, -1 });
    svm.setReplace(new boolean[] { false, false, false, false });
    svm.setCompatible(true);
    String javaScriptStepPid = registry.getPluginId(StepPluginType.class, svm);
    StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, svm);
    transMeta.addStep(javaScriptStep);
    TransHopMeta hi1 = new TransHopMeta(injectorStep, javaScriptStep);
    transMeta.addTransHop(hi1);
    // 
    // Create a dummy step
    // 
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
    transMeta.addTransHop(hi2);
    // Now execute the transformation...
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(null);
    StepInterface si;
    si = trans.getStepInterface(javaScriptStepname, 0);
    RowStepCollector javaScriptRc = new RowStepCollector();
    si.addRowListener(javaScriptRc);
    si = trans.getStepInterface(dummyStepname, 0);
    RowStepCollector dummyRc = new RowStepCollector();
    si.addRowListener(dummyRc);
    RowProducer rp = trans.addRowProducer(injectorStepname, 0);
    trans.startThreads();
    // add rows
    List<RowMetaAndData> inputList = createData1();
    Iterator<RowMetaAndData> it = inputList.iterator();
    while (it.hasNext()) {
        RowMetaAndData rm = it.next();
        rp.putRow(rm.getRowMeta(), rm.getData());
    }
    rp.finished();
    trans.waitUntilFinished();
    List<RowMetaAndData> goldenImageRows = createResultData1();
    List<RowMetaAndData> resultRows1 = javaScriptRc.getRowsWritten();
    checkRows(resultRows1, goldenImageRows);
    List<RowMetaAndData> resultRows2 = dummyRc.getRowsRead();
    checkRows(resultRows2, goldenImageRows);
}
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 74 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class TextFileOutputIT method createDummyStep.

/**
 * Create a dummy step for this class.
 *
 * @param name
 * @param registry
 * @return
 */
private StepMeta createDummyStep(String name, PluginRegistry registry) {
    // Create a dummy step 1 and add it to the tranMeta
    String dummyStepName = "dummy step";
    DummyTransMeta dm1 = new DummyTransMeta();
    String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
    StepMeta dummyStep = new StepMeta(dummyPid1, dummyStepName, dm1);
    return dummyStep;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)

Example 75 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta in project pentaho-kettle by pentaho.

the class OptimizationLevelIT method testOptimizationLevel.

/**
 * Creates the transformation needed to test the java script step with an optimization level set.
 *
 * @param optimizationLevel
 * @return
 * @throws KettleException
 */
private List<CheckResultInterface> testOptimizationLevel(String optimizationLevel) throws KettleException {
    KettleEnvironment.init();
    // Create a new transformation...
    TransMeta transMeta = new TransMeta();
    transMeta.setName("Test optimization level exception handling");
    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 javascript step
    String javaScriptStepname = "javascript step";
    // Create the meta and populate
    ScriptValuesMetaMod scriptValuesMetaMod = new ScriptValuesMetaMod();
    ScriptValuesScript[] js = new ScriptValuesScript[] { new ScriptValuesScript(ScriptValuesScript.TRANSFORM_SCRIPT, "script", "var str = string;\n" + "var bool = LuhnCheck(str);") };
    scriptValuesMetaMod.setJSScripts(js);
    scriptValuesMetaMod.setFieldname(new String[] { "bool" });
    scriptValuesMetaMod.setRename(new String[] { "" });
    scriptValuesMetaMod.setType(new int[] { ValueMetaInterface.TYPE_BOOLEAN });
    scriptValuesMetaMod.setLength(new int[] { -1 });
    scriptValuesMetaMod.setPrecision(new int[] { -1 });
    scriptValuesMetaMod.setReplace(new boolean[] { false });
    scriptValuesMetaMod.setCompatible(false);
    scriptValuesMetaMod.setOptimizationLevel(optimizationLevel);
    // Create the step meta
    String javaScriptStepPid = registry.getPluginId(StepPluginType.class, scriptValuesMetaMod);
    StepMeta javaScriptStep = new StepMeta(javaScriptStepPid, javaScriptStepname, scriptValuesMetaMod);
    // Create a dummy step
    String dummyStepname = "dummy step";
    DummyTransMeta dm = new DummyTransMeta();
    String dummyPid = registry.getPluginId(StepPluginType.class, dm);
    StepMeta dummyStep = new StepMeta(dummyPid, dummyStepname, dm);
    transMeta.addStep(dummyStep);
    // hop the steps that were created
    TransHopMeta hi2 = new TransHopMeta(javaScriptStep, dummyStep);
    transMeta.addTransHop(hi2);
    // We use an existing test that creates data: we'll use that data here
    JavaScriptSpecialIT javaScriptSpecialTest = new JavaScriptSpecialIT();
    List<RowMetaAndData> inputList = javaScriptSpecialTest.createData1();
    // RowMetaInterface rowMetaInterface = null;
    // This is the collection of error messages that may be generated
    // and other things that the check method will need
    List<CheckResultInterface> remarks = new ArrayList<CheckResultInterface>();
    String[] input = new String[] { injectorStepname };
    String[] output = new String[] {};
    // We get the row meta and data....
    Iterator<RowMetaAndData> it = inputList.iterator();
    if (it.hasNext()) {
        RowMetaAndData rowMetaAndData = it.next();
        // .... and then call the scriptValuesMetaMod's check method
        scriptValuesMetaMod.check(remarks, transMeta, javaScriptStep, rowMetaAndData.getRowMeta(), input, output, null, transMeta, null, null);
    } else {
        fail("No data in the inputList");
    }
    // we then return the remarks made by scriptValuesMetaMod.check(....);
    return remarks;
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) InjectorMeta(org.pentaho.di.trans.steps.injector.InjectorMeta) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) TransHopMeta(org.pentaho.di.trans.TransHopMeta) CheckResultInterface(org.pentaho.di.core.CheckResultInterface)

Aggregations

DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)85 StepMeta (org.pentaho.di.trans.step.StepMeta)84 TransMeta (org.pentaho.di.trans.TransMeta)53 TransHopMeta (org.pentaho.di.trans.TransHopMeta)52 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)49 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)46 Trans (org.pentaho.di.trans.Trans)46 StepInterface (org.pentaho.di.trans.step.StepInterface)46 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)45 RowStepCollector (org.pentaho.di.trans.RowStepCollector)42 InjectorMeta (org.pentaho.di.trans.steps.injector.InjectorMeta)38 RowProducer (org.pentaho.di.trans.RowProducer)36 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)11 UniqueRowsMeta (org.pentaho.di.trans.steps.uniquerows.UniqueRowsMeta)7 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)6 PartitionSchema (org.pentaho.di.partition.PartitionSchema)5 StepPartitioningMeta (org.pentaho.di.trans.step.StepPartitioningMeta)5 GetVariableMeta (org.pentaho.di.trans.steps.getvariable.GetVariableMeta)5 FieldDefinition (org.pentaho.di.trans.steps.getvariable.GetVariableMeta.FieldDefinition)5