Search in sources :

Example 51 with DummyTransMeta

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

the class SwitchCaseMetaTest method testsearchInfoAndTargetStepsTwice.

// Note - cloneTest removed because it's now covered by the load/save tester
@Test
public void testsearchInfoAndTargetStepsTwice() {
    StepMetaInterface defStep = new DummyTransMeta();
    StepMeta stepMeta = new StepMeta("id", "default", defStep);
    SwitchCaseMeta meta = new SwitchCaseMeta();
    meta.allocate();
    meta.setDefaultTargetStepname(stepMeta.getName());
    meta.searchInfoAndTargetSteps(Collections.singletonList(stepMeta));
    // would throw npe
    meta.searchInfoAndTargetSteps(Collections.singletonList(stepMeta));
}
Also used : StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 52 with DummyTransMeta

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

the class SwitchCaseTest method testCreateOutputValueMappingWithBinaryType.

@Test
public void testCreateOutputValueMappingWithBinaryType() throws KettleException, URISyntaxException, ParserConfigurationException, SAXException, IOException {
    SwitchCaseCustom krasavez = new SwitchCaseCustom(mockHelper);
    // load step info value-case mapping from xml.
    List<DatabaseMeta> emptyList = new ArrayList<DatabaseMeta>();
    krasavez.meta.loadXML(loadStepXmlMetadata("SwitchCaseBinaryTest.xml"), emptyList, mock(IMetaStore.class));
    KeyToRowSetMap expectedNN = new KeyToRowSetMap();
    Set<RowSet> nulls = new HashSet<RowSet>();
    // create real steps for all targets
    List<SwitchCaseTarget> list = krasavez.meta.getCaseTargets();
    for (SwitchCaseTarget item : list) {
        StepMetaInterface smInt = new DummyTransMeta();
        StepMeta stepMeta = new StepMeta(item.caseTargetStepname, smInt);
        item.caseTargetStep = stepMeta;
        // create and put row set for this
        RowSet rw = new QueueRowSet();
        krasavez.map.put(item.caseTargetStepname, rw);
        // null values goes to null rowset
        if (item.caseValue != null) {
            expectedNN.put(item.caseValue, rw);
        } else {
            nulls.add(rw);
        }
    }
    // create default step
    StepMetaInterface smInt = new DummyTransMeta();
    StepMeta stepMeta = new StepMeta(krasavez.meta.getDefaultTargetStepname(), smInt);
    krasavez.meta.setDefaultTargetStep(stepMeta);
    RowSet rw = new QueueRowSet();
    krasavez.map.put(krasavez.meta.getDefaultTargetStepname(), rw);
    krasavez.createOutputValueMapping();
    // inspect step output data:
    Set<RowSet> ones = krasavez.data.outputMap.get("1");
    assertEquals("Output map for 1 values contains 2 row sets", 2, ones.size());
    Set<RowSet> zeros = krasavez.data.outputMap.get("0");
    assertEquals("Output map for 0 values contains 1 row sets", 1, zeros.size());
    assertEquals("Null row set contains 0 items: ", 2, krasavez.data.nullRowSetSet.size());
    assertEquals("We have at least one default rowset", 1, krasavez.data.defaultRowSetSet.size());
    // check that rowsets data is correct:
    Set<RowSet> rowsets = expectedNN.get("1");
    for (RowSet rowset : rowsets) {
        assertTrue("Output map for 1 values contains expected row set", ones.contains(rowset));
    }
    rowsets = expectedNN.get("0");
    for (RowSet rowset : rowsets) {
        assertTrue("Output map for 0 values contains expected row set", zeros.contains(rowset));
    }
    for (RowSet rowset : krasavez.data.nullRowSetSet) {
        assertTrue("Output map for null values contains expected row set", nulls.contains(rowset));
    }
    // we have already check that there is only one item.
    for (RowSet rowset : krasavez.data.defaultRowSetSet) {
        assertTrue("Output map for default case contains expected row set", rowset.equals(rw));
    }
}
Also used : ArrayList(java.util.ArrayList) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 53 with DummyTransMeta

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

the class SwitchCaseTest method processRow_NullsArePutIntoDefaultWhenNotSpecified.

@Test
public void processRow_NullsArePutIntoDefaultWhenNotSpecified() throws Exception {
    SwitchCaseCustom step = new SwitchCaseCustom(mockHelper);
    step.meta.loadXML(loadStepXmlMetadata("SwitchCaseTest_PDI-12671.xml"), Collections.<DatabaseMeta>emptyList(), mock(IMetaStore.class));
    List<RowSet> outputRowSets = new LinkedList<RowSet>();
    for (SwitchCaseTarget item : step.meta.getCaseTargets()) {
        StepMetaInterface smInt = new DummyTransMeta();
        item.caseTargetStep = new StepMeta(item.caseTargetStepname, smInt);
        RowSet rw = new QueueRowSet();
        step.map.put(item.caseTargetStepname, rw);
        outputRowSets.add(rw);
    }
    // create a default step
    StepMetaInterface smInt = new DummyTransMeta();
    StepMeta stepMeta = new StepMeta(step.meta.getDefaultTargetStepname(), smInt);
    step.meta.setDefaultTargetStep(stepMeta);
    RowSet defaultRowSet = new QueueRowSet();
    step.map.put(step.meta.getDefaultTargetStepname(), defaultRowSet);
    step.input.add(new Object[] { null });
    step.processRow();
    assertEquals(1, defaultRowSet.size());
    for (RowSet rowSet : outputRowSets) {
        assertEquals(0, rowSet.size());
    }
    assertNull(defaultRowSet.getRow()[0]);
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMetaInterface(org.pentaho.di.trans.step.StepMetaInterface) IMetaStore(org.pentaho.metastore.api.IMetaStore) StepMeta(org.pentaho.di.trans.step.StepMeta) LinkedList(java.util.LinkedList) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

Example 54 with DummyTransMeta

use of org.pentaho.di.trans.steps.dummytrans.DummyTransMeta 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 55 with DummyTransMeta

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

the class StringSearcherTest method testSearchConditionCase.

@Test
public void testSearchConditionCase() {
    String dummyStepname = "Output";
    DummyTransMeta dummyMeta = new DummyTransMeta();
    String dummyStepPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, dummyMeta);
    StepMeta dummyStep = new StepMeta(dummyStepPid, dummyStepname, dummyMeta);
    List<StringSearchResult> stringList = new ArrayList<StringSearchResult>();
    StringSearcher.findMetaData(dummyStep, 0, stringList, dummyMeta, 0);
    int checkCount = 0;
    String aResult = null;
    // Check that it found a couple of fields and emits the values properly
    for (int i = 0; i < stringList.size(); i++) {
        aResult = stringList.get(i).toString();
        if (aResult.endsWith("Dummy (stepid)")) {
            checkCount++;
        } else if (aResult.endsWith("Output (name)")) {
            checkCount++;
        }
        if (checkCount == 2) {
            break;
        }
    }
    assertEquals(2, checkCount);
    FilterRowsMeta filterRowsMeta = new FilterRowsMeta();
    Condition condition = new Condition();
    condition.setNegated(false);
    condition.setLeftValuename("wibble_t");
    condition.setRightValuename("wobble_s");
    condition.setFunction(org.pentaho.di.core.Condition.FUNC_EQUAL);
    filterRowsMeta.setDefault();
    filterRowsMeta.setCondition(condition);
    String filterRowsPluginPid = PluginRegistry.getInstance().getPluginId(StepPluginType.class, filterRowsMeta);
    StepMeta filterRowsStep = new StepMeta(filterRowsPluginPid, "Filter Rows", filterRowsMeta);
    stringList.clear();
    StringSearcher.findMetaData(filterRowsStep, 0, stringList, filterRowsMeta, 0);
    checkCount = 0;
    for (int i = 0; i < stringList.size(); i++) {
        aResult = stringList.get(i).toString();
        if (aResult.endsWith("FilterRows (stepid)")) {
            checkCount++;
        } else if (aResult.endsWith("Filter Rows (name)")) {
            checkCount++;
        }
        if (checkCount == 2) {
            break;
        }
    }
    assertEquals(2, checkCount);
}
Also used : FilterRowsMeta(org.pentaho.di.trans.steps.filterrows.FilterRowsMeta) Condition(org.pentaho.di.core.Condition) ArrayList(java.util.ArrayList) StepMeta(org.pentaho.di.trans.step.StepMeta) DummyTransMeta(org.pentaho.di.trans.steps.dummytrans.DummyTransMeta) Test(org.junit.Test)

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