Search in sources :

Example 1 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.

the class XmlJoinOmitNullValuesTest method doTest.

private void doTest(final String sourceXml, final String targetXml, final String expectedXml) throws KettleException {
    XMLJoin spy = spy(new XMLJoin(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans));
    doReturn(createSourceRowSet(sourceXml)).when(spy).findInputRowSet("source");
    doReturn(createTargetRowSet(targetXml)).when(spy).findInputRowSet("target");
    XMLJoinMeta stepMeta = smh.initStepMetaInterface;
    when(stepMeta.getSourceXMLstep()).thenReturn("source");
    when(stepMeta.getTargetXMLstep()).thenReturn("target");
    when(stepMeta.getSourceXMLfield()).thenReturn("sourceField");
    when(stepMeta.getTargetXMLfield()).thenReturn("targetField");
    when(stepMeta.getValueXMLfield()).thenReturn("resultField");
    when(stepMeta.getTargetXPath()).thenReturn("//root");
    when(stepMeta.isOmitNullValues()).thenReturn(true);
    spy.init(stepMeta, smh.initStepDataInterface);
    spy.addRowListener(new RowAdapter() {

        @Override
        public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
            Assert.assertEquals(expectedXml, row[0]);
        }
    });
    Assert.assertTrue(spy.processRow(stepMeta, smh.initStepDataInterface));
    Assert.assertFalse(spy.processRow(stepMeta, smh.initStepDataInterface));
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface)

Example 2 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.

the class TransDebugMeta method addRowListenersToTransformation.

public synchronized void addRowListenersToTransformation(final Trans trans) {
    final TransDebugMeta self = this;
    // 
    for (final StepMeta stepMeta : stepDebugMetaMap.keySet()) {
        final StepDebugMeta stepDebugMeta = stepDebugMetaMap.get(stepMeta);
        // 
        for (StepInterface baseStep : trans.findBaseSteps(stepMeta.getName())) {
            baseStep.addRowListener(new RowAdapter() {

                public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                    try {
                        // This block of code is called whenever there is a row written by the step
                        // So we want to execute the debugging actions that are specified by the step...
                        // 
                        int rowCount = stepDebugMeta.getRowCount();
                        if (stepDebugMeta.isReadingFirstRows() && rowCount > 0) {
                            int bufferSize = stepDebugMeta.getRowBuffer().size();
                            if (bufferSize < rowCount) {
                                // This is the classic preview mode.
                                // We add simply add the row to the buffer.
                                // 
                                stepDebugMeta.setRowBufferMeta(rowMeta);
                                stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
                            } else {
                                // pause the transformation...
                                // 
                                trans.pauseRunning();
                                // Also call the pause / break-point listeners on the step debugger...
                                // 
                                stepDebugMeta.fireBreakPointListeners(self);
                            }
                        } else if (stepDebugMeta.isPausingOnBreakPoint() && stepDebugMeta.getCondition() != null) {
                            // 
                            if (rowCount > 0) {
                                // Keep a number of rows in memory
                                // Store them in a reverse order to keep it intuitive for the user.
                                // 
                                stepDebugMeta.setRowBufferMeta(rowMeta);
                                stepDebugMeta.getRowBuffer().add(0, rowMeta.cloneRow(row));
                                // Only keep a number of rows in memory
                                // If we have too many, remove the last (oldest)
                                // 
                                int bufferSize = stepDebugMeta.getRowBuffer().size();
                                if (bufferSize > rowCount) {
                                    stepDebugMeta.getRowBuffer().remove(bufferSize - 1);
                                }
                            } else {
                                // 
                                if (stepDebugMeta.getRowBuffer().isEmpty()) {
                                    stepDebugMeta.getRowBuffer().add(rowMeta.cloneRow(row));
                                } else {
                                    stepDebugMeta.getRowBuffer().set(0, rowMeta.cloneRow(row));
                                }
                            }
                            // 
                            if (stepDebugMeta.getCondition().evaluate(rowMeta, row)) {
                                // We hit the break-point: pause the transformation
                                // 
                                trans.pauseRunning();
                                // Also fire off the break point listeners...
                                // 
                                stepDebugMeta.fireBreakPointListeners(self);
                            }
                        }
                    } catch (KettleException e) {
                        throw new KettleStepException(e);
                    }
                }
            });
        }
    }
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta)

Example 3 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter in project pentaho-kettle by pentaho.

the class RowGeneratorUnitTest method doesNotWriteRowOnTimeWhenStopped.

@Test
public void doesNotWriteRowOnTimeWhenStopped() throws KettleException, InterruptedException {
    TransMeta transMeta = new TransMeta(getClass().getResource("safe-stop.ktr").getPath());
    Trans trans = new Trans(transMeta);
    trans.prepareExecution(new String[] {});
    trans.getSteps().get(1).step.addRowListener(new RowAdapter() {

        @Override
        public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
            trans.safeStop();
        }
    });
    trans.startThreads();
    trans.waitUntilFinished();
    assertEquals(1, trans.getSteps().get(0).step.getLinesWritten());
    assertEquals(1, trans.getSteps().get(1).step.getLinesRead());
}
Also used : KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowAdapter(org.pentaho.di.trans.step.RowAdapter) TransMeta(org.pentaho.di.trans.TransMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Trans(org.pentaho.di.trans.Trans) Test(org.junit.Test)

Example 4 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter 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 5 with RowAdapter

use of org.pentaho.di.trans.step.RowAdapter 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

RowAdapter (org.pentaho.di.trans.step.RowAdapter)24 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)22 KettleStepException (org.pentaho.di.core.exception.KettleStepException)21 KettleException (org.pentaho.di.core.exception.KettleException)16 RowSet (org.pentaho.di.core.RowSet)9 RowMeta (org.pentaho.di.core.row.RowMeta)9 Trans (org.pentaho.di.trans.Trans)7 StepInterface (org.pentaho.di.trans.step.StepInterface)7 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)6 Test (org.junit.Test)5 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)5 ArrayList (java.util.ArrayList)4 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)4 KettleValueException (org.pentaho.di.core.exception.KettleValueException)4 StepMeta (org.pentaho.di.trans.step.StepMeta)4 IOException (java.io.IOException)3 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)3 TransMeta (org.pentaho.di.trans.TransMeta)3 ParseException (java.text.ParseException)2 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)2