Search in sources :

Example 81 with ValueMetaNumber

use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.

the class CalculatorBackwardCompatibilityUnitTest method assertRoundStd2.

public void assertRoundStd2(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_STD_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 82 with ValueMetaNumber

use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.

the class CalculatorUnitTest method assertRoundGeneral.

public void assertRoundGeneral(final Object expectedResult, final int calcFunction, final Number value, final Long precision, final Long roundingMode, final int valueDataType, final int functionDataType) throws KettleException {
    final String msg = getKettleTypeName(valueDataType) + "->" + getKettleTypeName(functionDataType) + " ";
    final RowMeta inputRowMeta = new RowMeta();
    final List<Object> inputValues = new ArrayList<Object>(3);
    final String fieldValue = "Value";
    final ValueMetaInterface valueMeta;
    switch(valueDataType) {
        case ValueMetaInterface.TYPE_BIGNUMBER:
            valueMeta = new ValueMetaBigNumber(fieldValue);
            break;
        case ValueMetaInterface.TYPE_NUMBER:
            valueMeta = new ValueMetaNumber(fieldValue);
            break;
        case ValueMetaInterface.TYPE_INTEGER:
            valueMeta = new ValueMetaInteger(fieldValue);
            break;
        default:
            throw new IllegalArgumentException(msg + "Unexpected value dataType: " + value.getClass().getName() + ". Long, Double or BigDecimal expected.");
    }
    inputRowMeta.addValueMeta(valueMeta);
    inputValues.add(value);
    final String fieldPrecision;
    final ValueMetaInteger precisionMeta;
    if (precision == null) {
        fieldPrecision = null;
        precisionMeta = null;
    } else {
        fieldPrecision = "Precision";
        precisionMeta = new ValueMetaInteger(fieldPrecision);
        inputRowMeta.addValueMeta(precisionMeta);
        inputValues.add(precision);
    }
    final String fieldRoundingMode;
    final ValueMetaInteger roundingModeMeta;
    if (roundingMode == null) {
        fieldRoundingMode = null;
        roundingModeMeta = null;
    } else {
        fieldRoundingMode = "RoundingMode";
        roundingModeMeta = new ValueMetaInteger(fieldRoundingMode);
        inputRowMeta.addValueMeta(roundingModeMeta);
        inputValues.add(roundingMode);
    }
    RowSet inputRowSet = smh.getMockInputRowSet(inputValues.toArray());
    inputRowSet.setRowMeta(inputRowMeta);
    final String fieldA = inputRowMeta.size() > 0 ? inputRowMeta.getValueMetaList().get(0).getName() : null;
    final String fieldB = inputRowMeta.size() > 1 ? inputRowMeta.getValueMetaList().get(1).getName() : null;
    final String fieldC = inputRowMeta.size() > 2 ? inputRowMeta.getValueMetaList().get(2).getName() : null;
    final int resultDataType = functionDataType;
    final String fieldResult = "test";
    final int expectedResultRowSize = inputRowMeta.size() + 1;
    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(fieldResult, calcFunction, fieldA, fieldB, fieldC, resultDataType, 2, 0, false, "", "", "", "") });
    // Verify output
    try {
        calculator.addRowListener(new RowAdapter() {

            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                assertEquals(msg + " resultRowSize", expectedResultRowSize, rowMeta.size());
                final int fieldResultIndex = rowMeta.size() - 1;
                assertEquals(msg + " fieldResult", fieldResult, rowMeta.getValueMeta(fieldResultIndex).getName());
                assertEquals(msg, expectedResult, row[fieldResultIndex]);
            }
        });
        calculator.processRow(meta, new CalculatorData());
    } catch (KettleException ke) {
        ke.printStackTrace();
        fail(msg + ke.getMessage());
    }
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 83 with ValueMetaNumber

use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.

the class CalculatorUnitTest method assertCalculatorReminder.

private void assertCalculatorReminder(final Object expectedResult, final Object[] values, final int[] types) throws Exception {
    RowMeta inputRowMeta = new RowMeta();
    for (int i = 0; i < types.length; i++) {
        switch(types[i]) {
            case ValueMetaInterface.TYPE_BIGNUMBER:
                inputRowMeta.addValueMeta(new ValueMetaBigNumber("f" + i));
                break;
            case ValueMetaInterface.TYPE_NUMBER:
                inputRowMeta.addValueMeta(new ValueMetaNumber("f" + i));
                break;
            case ValueMetaInterface.TYPE_INTEGER:
                inputRowMeta.addValueMeta(new ValueMetaInteger("f" + i));
                break;
            default:
                throw new IllegalArgumentException("Unexpected value dataType: " + types[i] + ". Long, Double or BigDecimal expected.");
        }
    }
    RowSet inputRowSet = null;
    try {
        inputRowSet = smh.getMockInputRowSet(new Object[][] { { values[0], values[1] } });
    } catch (Exception pe) {
        pe.printStackTrace();
        fail();
    }
    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("res", CalculatorMetaFunction.CALC_REMAINDER, "f0", "f1", null, ValueMetaInterface.TYPE_NUMBER, 0, 0, false, "", "", "", "") });
    // Verify output
    try {
        calculator.addRowListener(new RowAdapter() {

            @Override
            public void rowWrittenEvent(RowMetaInterface rowMeta, Object[] row) throws KettleStepException {
                try {
                    assertEquals(expectedResult, row[2]);
                } catch (Exception pe) {
                    throw new KettleStepException(pe);
                }
            }
        });
        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) KettleException(org.pentaho.di.core.exception.KettleException) ParseException(java.text.ParseException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 84 with ValueMetaNumber

use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.

the class CheckSumTest method testHexOutput_sha1_compatibilityMode.

@Test
public void testHexOutput_sha1_compatibilityMode() throws Exception {
    MockRowListener results = executeHexTest(3, true, "xyz", new ValueMetaString("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("66FD7417FD7E024C46526C2F6D35FD754FFD52FD", results.getWritten().get(0)[1]);
    results = executeHexTest(3, true, 10.8, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("78FDFD3DFDFDE80656FD0AFD5AFDFD10FDFD68", results.getWritten().get(0)[1]);
    results = executeHexTest(3, true, 10.82, new ValueMetaNumber("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("74FD3D4C2DFD7CFD31FD563A72FD5DFD461F04FD", results.getWritten().get(0)[1]);
    byte[] input = IOUtils.toByteArray(getFile("/org/pentaho/di/trans/steps/loadfileinput/files/pentaho_splash.png").getContent().getInputStream());
    results = executeHexTest(3, true, input, new ValueMetaBinary("test"), false);
    assertEquals(1, results.getWritten().size());
    assertEquals("FD7D0B5B60663BFD5E0DFDFD3B44FD673738315A", results.getWritten().get(0)[1]);
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) Test(org.junit.Test)

Example 85 with ValueMetaNumber

use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.

the class CheckSumTest method testHexOutput_sha256_oldChecksumBehaviourMode.

@Test
public void testHexOutput_sha256_oldChecksumBehaviourMode() throws Exception {
    MockRowListener results = executeHexTest(4, false, "xyz", new ValueMetaString("test"), true);
    assertEquals(1, results.getWritten().size());
    assertEquals("3608bca1e44ea6c4d268eb6db02260269892c0b42b86bbf1e77a6fa16c3c9282", results.getWritten().get(0)[1]);
    results = executeHexTest(4, false, 10.8, new ValueMetaNumber("test"), true);
    assertEquals(1, results.getWritten().size());
    assertEquals("b52b603f9ec86c382a8483cad4f788f2f927535a76ad1388caedcef5e3c3c813", results.getWritten().get(0)[1]);
    results = executeHexTest(4, false, 10.82, new ValueMetaNumber("test"), true);
    assertEquals(1, results.getWritten().size());
    assertEquals("45cbb96ff9625490cd675a7a39fecad6c167c1ed9b8957f53224fcb3e4a1e4a1", results.getWritten().get(0)[1]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) Test(org.junit.Test)

Aggregations

ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)95 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)75 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)52 Test (org.junit.Test)51 RowMeta (org.pentaho.di.core.row.RowMeta)39 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)34 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)34 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)32 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)30 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)25 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)16 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)15 KettleException (org.pentaho.di.core.exception.KettleException)12 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)11 KettleStepException (org.pentaho.di.core.exception.KettleStepException)7 ArrayList (java.util.ArrayList)6 Date (java.util.Date)6 RowSet (org.pentaho.di.core.RowSet)6 RowAdapter (org.pentaho.di.trans.step.RowAdapter)6