Search in sources :

Example 36 with RowSet

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

the class TransExecutorUnitTest method collectsExecutionResults.

@Test
public void collectsExecutionResults() throws Exception {
    prepareOneRowForExecutor();
    StepMeta parentStepMeta = mock(StepMeta.class);
    when(parentStepMeta.getName()).thenReturn("parentStepMeta");
    meta.setParentStepMeta(parentStepMeta);
    internalResult.setResult(true);
    meta.setExecutionResultField("executionResultField");
    internalResult.setNrErrors(1);
    meta.setExecutionNrErrorsField("executionNrErrorsField");
    internalResult.setNrLinesRead(2);
    meta.setExecutionLinesReadField("executionLinesReadField");
    internalResult.setNrLinesWritten(3);
    meta.setExecutionLinesWrittenField("executionLinesWrittenField");
    internalResult.setNrLinesInput(4);
    meta.setExecutionLinesInputField("executionLinesInputField");
    internalResult.setNrLinesOutput(5);
    meta.setExecutionLinesOutputField("executionLinesOutputField");
    internalResult.setNrLinesRejected(6);
    meta.setExecutionLinesRejectedField("executionLinesRejectedField");
    internalResult.setNrLinesUpdated(7);
    meta.setExecutionLinesUpdatedField("executionLinesUpdatedField");
    internalResult.setNrLinesDeleted(8);
    meta.setExecutionLinesDeletedField("executionLinesDeletedField");
    internalResult.setNrFilesRetrieved(9);
    meta.setExecutionFilesRetrievedField("executionFilesRetrievedField");
    internalResult.setExitStatus(10);
    meta.setExecutionExitStatusField("executionExitStatusField");
    RowSet rowSet = new QueueRowSet();
    // any value except null
    StepMeta stepMeta = mockStepAndMapItToRowSet("stepMetaMock", rowSet);
    meta.setExecutionResultTargetStepMeta(stepMeta);
    executor.init(meta, data);
    executor.setInputRowMeta(new RowMeta());
    assertTrue("Passing one line at first time", executor.processRow(meta, data));
    assertFalse("Executing the internal trans during the second round", executor.processRow(meta, data));
    Object[] resultsRow = rowSet.getRowImmediate();
    assertNotNull(resultsRow);
    assertNull("Only one row is expected", rowSet.getRowImmediate());
    assertEquals(internalResult.getResult(), resultsRow[0]);
    assertEquals(internalResult.getNrErrors(), resultsRow[1]);
    assertEquals(internalResult.getNrLinesRead(), resultsRow[2]);
    assertEquals(internalResult.getNrLinesWritten(), resultsRow[3]);
    assertEquals(internalResult.getNrLinesInput(), resultsRow[4]);
    assertEquals(internalResult.getNrLinesOutput(), resultsRow[5]);
    assertEquals(internalResult.getNrLinesRejected(), resultsRow[6]);
    assertEquals(internalResult.getNrLinesUpdated(), resultsRow[7]);
    assertEquals(internalResult.getNrLinesDeleted(), resultsRow[8]);
    assertEquals(internalResult.getNrFilesRetrieved(), resultsRow[9]);
    assertEquals(internalResult.getExitStatus(), ((Number) resultsRow[10]).intValue());
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 37 with RowSet

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

the class TransExecutorUnitTest method collectsResultsFromInternalTransformation.

@Test
public void collectsResultsFromInternalTransformation() throws Exception {
    prepareOneRowForExecutor();
    RowMetaAndData expectedResult = new RowMetaAndData(new RowMeta(), "fake result");
    internalResult.getRows().add(expectedResult);
    RowSet rowSet = new QueueRowSet();
    // any value except null
    StepMeta stepMeta = mockStepAndMapItToRowSet("stepMetaMock", rowSet);
    meta.setOutputRowsSourceStepMeta(stepMeta);
    executor.init(meta, data);
    executor.setInputRowMeta(new RowMeta());
    assertTrue("Passing one line at first time", executor.processRow(meta, data));
    assertFalse("Executing the internal trans during the second round", executor.processRow(meta, data));
    Object[] resultsRow = rowSet.getRowImmediate();
    assertNotNull(resultsRow);
    assertArrayEquals(expectedResult.getData(), resultsRow);
    assertNull("Only one row is expected", rowSet.getRowImmediate());
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 38 with RowSet

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

the class BaseStepTest method outputRowMetasAreNotSharedAmongSeveralStreams.

@Test
public void outputRowMetasAreNotSharedAmongSeveralStreams() throws Exception {
    RowSet rs1 = new SingleRowRowSet();
    RowSet rs2 = new SingleRowRowSet();
    when(mockHelper.trans.isRunning()).thenReturn(true);
    BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    baseStep.setStopped(false);
    baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_NONE);
    baseStep.setOutputRowSets(Arrays.asList(rs1, rs2));
    for (RowSet rowSet : baseStep.getOutputRowSets()) {
        assertNull("RowMeta should be null, since no calls were done", rowSet.getRowMeta());
    }
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("string"));
    rowMeta.addValueMeta(new ValueMetaInteger("integer"));
    baseStep.putRow(rowMeta, new Object[] { "a", 1 });
    RowMetaInterface meta1 = rs1.getRowMeta();
    RowMetaInterface meta2 = rs2.getRowMeta();
    assertNotNull(meta1);
    assertNotNull(meta2);
    // content is same
    for (ValueMetaInterface meta : meta1.getValueMetaList()) {
        assertTrue(meta.getName(), meta2.exists(meta));
    }
    // whereas instances differ
    assertFalse(meta1 == meta2);
}
Also used : SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 39 with RowSet

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

the class CalculatorBackwardCompatibilityUnitTest method assertRound2.

public void assertRound2(final double expectedResult, final double value, final long precision) throws KettleException {
    RowMeta inputRowMeta = new RowMeta();
    ValueMetaNumber valueMeta = new ValueMetaNumber("Value");
    ValueMetaInteger precisionMeta = new ValueMetaInteger("Precision");
    inputRowMeta.addValueMeta(valueMeta);
    inputRowMeta.addValueMeta(precisionMeta);
    RowSet inputRowSet = smh.getMockInputRowSet(new Object[] { value, precision });
    inputRowSet.setRowMeta(inputRowMeta);
    Calculator calculator = new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    calculator.addRowSetToInputRowSets(inputRowSet);
    calculator.setInputRowMeta(inputRowMeta);
    calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);
    CalculatorMeta meta = new CalculatorMeta();
    meta.setCalculation(new CalculatorMetaFunction[] { new CalculatorMetaFunction("test", CalculatorMetaFunction.CALC_ROUND_2, "Value", "Precision", null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "") });
    // Verify output
    try {
        calculator.addRowListener(new RowAdapter() {

            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                assertEquals(expectedResult, row[2]);
            }
        });
        calculator.processRow(meta, new CalculatorData());
    } catch (KettleException ke) {
        ke.printStackTrace();
        fail();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 40 with RowSet

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

the class CalculatorBackwardCompatibilityUnitTest method assertRound.

public void assertRound(final double expectedResult, final double value) throws KettleException {
    RowMeta inputRowMeta = new RowMeta();
    ValueMetaNumber valueMeta = new ValueMetaNumber("Value");
    inputRowMeta.addValueMeta(valueMeta);
    RowSet inputRowSet = smh.getMockInputRowSet(new Object[] { value });
    inputRowSet.setRowMeta(inputRowMeta);
    Calculator calculator = new Calculator(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    calculator.addRowSetToInputRowSets(inputRowSet);
    calculator.setInputRowMeta(inputRowMeta);
    calculator.init(smh.initStepMetaInterface, smh.initStepDataInterface);
    CalculatorMeta meta = new CalculatorMeta();
    meta.setCalculation(new CalculatorMetaFunction[] { new CalculatorMetaFunction("test", CalculatorMetaFunction.CALC_ROUND_1, "Value", null, null, ValueMetaInterface.TYPE_NUMBER, 2, 0, false, "", "", "", "") });
    // Verify output
    try {
        calculator.addRowListener(new RowAdapter() {

            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                assertEquals(expectedResult, row[1]);
            }
        });
        calculator.processRow(meta, new CalculatorData());
    } catch (KettleException ke) {
        ke.printStackTrace();
        fail();
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter)

Aggregations

RowSet (org.pentaho.di.core.RowSet)109 Test (org.junit.Test)43 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)40 RowMeta (org.pentaho.di.core.row.RowMeta)34 QueueRowSet (org.pentaho.di.core.QueueRowSet)26 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleException (org.pentaho.di.core.exception.KettleException)23 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)21 KettleStepException (org.pentaho.di.core.exception.KettleStepException)19 ArrayList (java.util.ArrayList)16 StepInterface (org.pentaho.di.trans.step.StepInterface)13 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)12 StepMeta (org.pentaho.di.trans.step.StepMeta)11 SingleRowRowSet (org.pentaho.di.core.SingleRowRowSet)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)9 RowAdapter (org.pentaho.di.trans.step.RowAdapter)9 Matchers.anyString (org.mockito.Matchers.anyString)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 IOException (java.io.IOException)6 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)6