Search in sources :

Example 16 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class StreamLookupTest method doTest.

private void doTest(boolean memoryPreservationActive, boolean binaryLookupStream, boolean binaryDataStream) throws KettleException {
    StreamLookup step = new StreamLookup(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.initStepDataInterface);
    step.addRowSetToInputRowSets(mockLookupRowSet(binaryLookupStream));
    step.addRowSetToInputRowSets(mockDataRowSet(binaryDataStream));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    StreamLookupMeta meta = mockProcessRowMeta(memoryPreservationActive);
    StreamLookupData data = new StreamLookupData();
    data.readLookupValues = true;
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    // Process rows and collect output
    int rowNumber = 0;
    String[] expectedOutput = { "Name", "", "Value" };
    while (step.processRow(meta, data)) {
        Object[] rowData = outputRowSet.getRow();
        if (rowData != null) {
            RowMetaInterface rowMeta = outputRowSet.getRowMeta();
            Assert.assertEquals("Output row is of wrong size", 3, rowMeta.size());
            rowNumber++;
            // Verify output
            for (int valueIndex = 0; valueIndex < rowMeta.size(); valueIndex++) {
                String expectedValue = expectedOutput[valueIndex] + rowNumber;
                Object actualValue = rowMeta.getValueMeta(valueIndex).convertToNormalStorageType(rowData[valueIndex]);
                Assert.assertEquals("Unexpected value at row " + rowNumber + " position " + valueIndex, expectedValue, actualValue);
            }
        }
    }
    Assert.assertEquals("Incorrect output row number", 2, rowNumber);
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString)

Example 17 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class StringOperationsTest method testProcessBinaryInput.

@Test
public void testProcessBinaryInput() throws KettleException {
    StringOperations step = new StringOperations(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.addRowSetToInputRowSets(mockInputRowSet());
    RowSet outputRowSet = new QueueRowSet();
    step.addRowSetToOutputRowSets(outputRowSet);
    StringOperationsMeta meta = mockStepMeta();
    StringOperationsData data = mockStepData();
    step.init(meta, data);
    boolean processResult;
    do {
        processResult = step.processRow(meta, data);
    } while (processResult);
    Assert.assertTrue(outputRowSet.isDone());
    Assert.assertTrue("Unexpected output", verifyOutput(new Object[][] { { "Value" } }, outputRowSet));
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 18 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet 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 19 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class PDI_15270_Test method doTest.

public void doTest(String content, String[] expected) throws Exception {
    RowSet output = new QueueRowSet();
    File tmp = createTestFile(encoding, content);
    try {
        CsvInputMeta meta = createMeta(tmp, createInputFileFields("f1", "f2", "f3"));
        CsvInputData data = new CsvInputData();
        csvInput.init(meta, data);
        csvInput.addRowSetToOutputRowSets(output);
        try {
            csvInput.processRow(meta, data);
        } finally {
            csvInput.dispose(meta, data);
        }
    } finally {
        tmp.delete();
    }
    Object[] row = output.getRowImmediate();
    assertNotNull(row);
    assertEquals(expected[0], row[0]);
    assertEquals(expected[1], row[1]);
    assertEquals(expected[2], row[2]);
    assertNull(output.getRowImmediate());
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) File(java.io.File)

Example 20 with QueueRowSet

use of org.pentaho.di.core.QueueRowSet in project pentaho-kettle by pentaho.

the class PDI5436Test method testCacheAllTable.

@Test
public void testCacheAllTable() throws KettleException {
    DatabaseLookup stepSpy = spy(new DatabaseLookup(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans));
    Database database = mockDatabase();
    doReturn(database).when(stepSpy).getDatabase(any(DatabaseMeta.class));
    stepSpy.addRowSetToInputRowSets(mockInputRowSet());
    stepSpy.setInputRowMeta(mockInputRowMeta());
    RowSet outputRowSet = new QueueRowSet();
    stepSpy.addRowSetToOutputRowSets(outputRowSet);
    StepMetaInterface meta = mockStepMeta();
    StepDataInterface data = smh.initStepDataInterface;
    Assert.assertTrue("Step init failed", stepSpy.init(meta, data));
    Assert.assertTrue("Error processing row", stepSpy.processRow(meta, data));
    Assert.assertEquals("Cache lookup failed", "value", outputRowSet.getRow()[2]);
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) Database(org.pentaho.di.core.database.Database) 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) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) Test(org.junit.Test)

Aggregations

QueueRowSet (org.pentaho.di.core.QueueRowSet)20 RowSet (org.pentaho.di.core.RowSet)18 Test (org.junit.Test)13 RowMeta (org.pentaho.di.core.row.RowMeta)5 StepMeta (org.pentaho.di.trans.step.StepMeta)5 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)4 File (java.io.File)3 SingleRowRowSet (org.pentaho.di.core.SingleRowRowSet)3 KettleException (org.pentaho.di.core.exception.KettleException)3 SimpleDateFormat (java.text.SimpleDateFormat)2 BlockingBatchingRowSet (org.pentaho.di.core.BlockingBatchingRowSet)2 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)2 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)2 StepDataInterface (org.pentaho.di.trans.step.StepDataInterface)2 StepInterface (org.pentaho.di.trans.step.StepInterface)2 StepMetaInterface (org.pentaho.di.trans.step.StepMetaInterface)2 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1