use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MetaInjectTest method setEntryValue_number.
@Test
public void setEntryValue_number() throws KettleValueException {
StepInjectionMetaEntry entry = mock(StepInjectionMetaEntry.class);
doReturn(ValueMetaInterface.TYPE_NUMBER).when(entry).getValueType();
RowMetaAndData row = createRowMetaAndData(new ValueMetaNumber(TEST_FIELD), new Double(1));
SourceStepField sourceField = new SourceStepField(TEST_SOURCE_STEP_NAME, TEST_FIELD);
MetaInject.setEntryValue(entry, row, sourceField);
verify(entry).setValue(1.0D);
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MemoryGroupByAggregationTest method testNullsAreZeroDefault.
@Test
public void testNullsAreZeroDefault() throws Exception {
variables.setVariable(Const.KETTLE_AGGREGATION_ALL_NULLS_ARE_ZERO, "Y");
addColumn(new ValueMetaInteger("nul"));
addColumn(new ValueMetaInteger("both"), -2L, 0L, null, 10L);
addColumn(new ValueMetaNumber("both_num"), -2.0, 0.0, null, 10.0);
RowMetaAndData output = runStep();
assertThat(output.getInteger("nul_min"), is(0L));
assertThat(output.getInteger("nul_max"), is(0L));
assertThat(output.getInteger("nul_sum"), is(0L));
assertThat(output.getInteger("nul_ave"), is(0L));
assertThat(output.getInteger("nul_count"), is(0L));
assertThat(output.getInteger("nul_count_any"), is(4L));
assertThat(output.getInteger("nul_count_distinct"), is(0L));
assertThat(output.getInteger("both_max"), is(10L));
assertThat(output.getInteger("both_min"), is(-2L));
assertThat(output.getInteger("both_sum"), is(8L));
assertThat(output.getInteger("both_ave"), is(2L));
assertThat(output.getInteger("both_count"), is(3L));
assertThat(output.getInteger("both_count_any"), is(4L));
assertThat(output.getInteger("both_count_distinct"), is(3L));
assertThat(output.getNumber("both_num_max", Double.NaN), is(10.0));
assertThat(output.getNumber("both_num_min", Double.NaN), is(-2.0));
assertThat(output.getNumber("both_num_sum", Double.NaN), is(8.0));
assertEquals(2.666666, output.getNumber("both_num_ave", Double.NaN), 0.000001);
assertThat(output.getInteger("both_num_count"), is(3L));
assertThat(output.getInteger("both_num_count_any"), is(4L));
assertThat(output.getInteger("both_num_count_distinct"), is(3L));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MemoryGroupByMetaTest method getInputRowMeta.
private RowMetaInterface getInputRowMeta() {
RowMetaInterface rm = new RowMeta();
rm.addValueMeta(new ValueMetaString("myGroupField2"));
rm.addValueMeta(new ValueMetaString("myGroupField1"));
rm.addValueMeta(new ValueMetaString("myString"));
rm.addValueMeta(new ValueMetaInteger("myInteger"));
rm.addValueMeta(new ValueMetaNumber("myNumber"));
rm.addValueMeta(new ValueMetaBigNumber("myBigNumber"));
rm.addValueMeta(new ValueMetaBinary("myBinary"));
rm.addValueMeta(new ValueMetaBoolean("myBoolean"));
rm.addValueMeta(new ValueMetaDate("myDate"));
rm.addValueMeta(new ValueMetaTimestamp("myTimestamp"));
rm.addValueMeta(new ValueMetaInternetAddress("myInternetAddress"));
return rm;
}
use of org.pentaho.di.core.row.value.ValueMetaNumber 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();
}
}
use of org.pentaho.di.core.row.value.ValueMetaNumber 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();
}
}
Aggregations