Search in sources :

Example 31 with ValueMetaBigNumber

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

the class AppendIT method createRowMetaInterface.

public RowMetaInterface createRowMetaInterface() {
    RowMetaInterface rm = new RowMeta();
    ValueMetaInterface[] valuesMeta = { new ValueMetaString("field1"), new ValueMetaInteger("field2"), new ValueMetaNumber("field3"), new ValueMetaDate("field4"), new ValueMetaBoolean("field5"), new ValueMetaBigNumber("field6"), new ValueMetaBigNumber("field7") };
    for (int i = 0; i < valuesMeta.length; i++) {
        rm.addValueMeta(valuesMeta[i]);
    }
    return rm;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 32 with ValueMetaBigNumber

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

the class BlockingStepIT method createRowMetaInterface.

public RowMetaInterface createRowMetaInterface() {
    RowMetaInterface rm = new RowMeta();
    ValueMetaInterface[] valuesMeta = { new ValueMetaString("field1"), new ValueMetaInteger("field2"), new ValueMetaNumber("field3"), new ValueMetaDate("field4"), new ValueMetaBoolean("field5"), new ValueMetaBigNumber("field6"), new ValueMetaBigNumber("field7") };
    for (int i = 0; i < valuesMeta.length; i++) {
        rm.addValueMeta(valuesMeta[i]);
    }
    return rm;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 33 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber 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 34 with ValueMetaBigNumber

use of org.pentaho.di.core.row.value.ValueMetaBigNumber 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)

Aggregations

ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)31 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)30 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)28 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)25 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)23 RowMeta (org.pentaho.di.core.row.RowMeta)21 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)18 Test (org.junit.Test)17 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)15 ValueMetaInternetAddress (org.pentaho.di.core.row.value.ValueMetaInternetAddress)14 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)13 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)13 BigDecimal (java.math.BigDecimal)6 ArrayList (java.util.ArrayList)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleException (org.pentaho.di.core.exception.KettleException)4 SQLException (java.sql.SQLException)3 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)3 BatchUpdateException (java.sql.BatchUpdateException)2