use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class ConditionTest method testPdi13227.
@Test
public void testPdi13227() throws Exception {
RowMetaInterface rowMeta1 = new RowMeta();
rowMeta1.addValueMeta(new ValueMetaNumber("name1"));
rowMeta1.addValueMeta(new ValueMetaNumber("name2"));
rowMeta1.addValueMeta(new ValueMetaNumber("name3"));
RowMetaInterface rowMeta2 = new RowMeta();
rowMeta2.addValueMeta(new ValueMetaNumber("name2"));
rowMeta2.addValueMeta(new ValueMetaNumber("name1"));
rowMeta2.addValueMeta(new ValueMetaNumber("name3"));
String left = "name1";
String right = "name3";
Condition condition = new Condition(left, Condition.FUNC_EQUAL, right, null);
assertTrue(condition.evaluate(rowMeta1, new Object[] { 1.0, 2.0, 1.0 }));
assertTrue(condition.evaluate(rowMeta2, new Object[] { 2.0, 1.0, 1.0 }));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MemoryGroupByAggregationTest method testDefault.
@Test
public void testDefault() throws Exception {
addColumn(new ValueMetaInteger("intg"), 0L, 1L, 1L, 10L);
addColumn(new ValueMetaInteger("nul"));
addColumn(new ValueMetaInteger("mix1"), -1L, 2L);
addColumn(new ValueMetaInteger("mix2"), null, 7L);
addColumn(new ValueMetaNumber("mix3"), -1.0, 2.5);
addColumn(new ValueMetaDate("date1"), new Date(1L), new Date(2L));
RowMetaAndData output = runStep();
assertThat(output.getInteger("intg_min"), is(0L));
assertThat(output.getInteger("intg_max"), is(10L));
assertThat(output.getInteger("intg_sum"), is(12L));
assertThat(output.getInteger("intg_ave"), is(3L));
assertThat(output.getInteger("intg_count"), is(4L));
assertThat(output.getInteger("intg_count_any"), is(4L));
assertThat(output.getInteger("intg_count_distinct"), is(3L));
assertThat(output.getInteger("nul_min"), nullValue());
assertThat(output.getInteger("nul_max"), nullValue());
assertThat(output.getInteger("nul_sum"), nullValue());
assertThat(output.getInteger("nul_ave"), nullValue());
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("mix1_max"), is(2L));
assertThat(output.getInteger("mix1_min"), is(-1L));
assertThat(output.getInteger("mix1_sum"), is(1L));
assertThat(output.getInteger("mix1_ave"), is(0L));
assertThat(output.getInteger("mix1_count"), is(2L));
assertThat(output.getInteger("mix1_count_any"), is(4L));
assertThat(output.getInteger("mix1_count_distinct"), is(2L));
assertThat(output.getInteger("mix2_max"), is(7L));
assertThat(output.getInteger("mix2_min"), is(7L));
assertThat(output.getInteger("mix2_sum"), is(7L));
assertThat(output.getNumber("mix2_ave", Double.NaN), is(7.0));
assertThat(output.getInteger("mix2_count"), is(1L));
assertThat(output.getInteger("mix2_count_any"), is(4L));
assertThat(output.getInteger("mix2_count_distinct"), is(1L));
assertThat(output.getNumber("mix3_max", Double.NaN), is(2.5));
assertThat(output.getNumber("mix3_min", Double.NaN), is(-1.0));
assertThat(output.getNumber("mix3_sum", Double.NaN), is(1.5));
assertThat(output.getNumber("mix3_ave", Double.NaN), is(0.75));
assertThat(output.getInteger("mix3_count"), is(2L));
assertThat(output.getInteger("mix3_count_any"), is(4L));
assertThat(output.getInteger("mix3_count_distinct"), is(2L));
assertThat(output.getNumber("date1_min", Double.NaN), is(1.0));
assertThat(output.getNumber("date1_max", Double.NaN), is(2.0));
assertThat(output.getNumber("date1_sum", Double.NaN), is(3.0));
assertThat(output.getNumber("date1_ave", Double.NaN), is(1.5));
assertThat(output.getInteger("date1_count"), is(2L));
assertThat(output.getInteger("date1_count_any"), is(4L));
assertThat(output.getInteger("date1_count_distinct"), is(2L));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MemoryGroupByAggregationTest method testCompatibility.
@Test
public void testCompatibility() throws KettleException {
variables.setVariable(Const.KETTLE_COMPATIBILITY_MEMORY_GROUP_BY_SUM_AVERAGE_RETURN_NUMBER_TYPE, "Y");
addColumn(new ValueMetaInteger("intg"), 0L, 1L, 1L, 10L);
addColumn(new ValueMetaInteger("nul"));
addColumn(new ValueMetaInteger("mix1"), -1L, 2L);
addColumn(new ValueMetaInteger("mix2"), null, 7L);
addColumn(new ValueMetaNumber("mix3"), -1.0, 2.5);
RowMetaAndData output = runStep();
assertThat(output.getInteger("intg_min"), is(0L));
assertThat(output.getInteger("intg_max"), is(10L));
assertThat(output.getInteger("intg_sum"), is(12L));
assertThat(output.getInteger("intg_ave"), is(3L));
assertThat(output.getInteger("intg_count"), is(4L));
assertThat(output.getInteger("intg_count_any"), is(4L));
assertThat(output.getInteger("intg_count_distinct"), is(3L));
assertThat(output.getInteger("nul_min"), nullValue());
assertThat(output.getInteger("nul_max"), nullValue());
assertThat(output.getInteger("nul_sum"), nullValue());
assertThat(output.getInteger("nul_ave"), nullValue());
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("mix1_max"), is(2L));
assertThat(output.getInteger("mix1_min"), is(-1L));
assertThat(output.getInteger("mix1_sum"), is(1L));
assertThat(output.getNumber("mix1_ave", Double.NaN), is(0.5));
assertThat(output.getInteger("mix1_count"), is(2L));
assertThat(output.getInteger("mix1_count_any"), is(4L));
assertThat(output.getInteger("mix1_count_distinct"), is(2L));
assertThat(output.getInteger("mix2_max"), is(7L));
assertThat(output.getInteger("mix2_min"), is(7L));
assertThat(output.getInteger("mix2_sum"), is(7L));
assertThat(output.getNumber("mix2_ave", Double.NaN), is(7.0));
assertThat(output.getInteger("mix2_count"), is(1L));
assertThat(output.getInteger("mix2_count_any"), is(4L));
assertThat(output.getInteger("mix2_count_distinct"), is(1L));
assertThat(output.getNumber("mix3_max", Double.NaN), is(2.5));
assertThat(output.getNumber("mix3_min", Double.NaN), is(-1.0));
assertThat(output.getNumber("mix3_sum", Double.NaN), is(1.5));
assertThat(output.getNumber("mix3_ave", Double.NaN), is(0.75));
assertThat(output.getInteger("mix3_count"), is(2L));
assertThat(output.getInteger("mix3_count_any"), is(4L));
assertThat(output.getInteger("mix3_count_distinct"), is(2L));
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class MySQLBulkLoaderTest method testNumberFormatting.
/**
* Default conversion mask for Number column type should be calculated according to length and precision.
* For example, for type NUMBER(6,3) conversion mask should be: " #000.000;-#000.000"
*/
@Test
public void testNumberFormatting() throws KettleException, IOException {
PluginRegistry.addPluginType(ValueMetaPluginType.getInstance());
PluginRegistry.init(false);
MySQLBulkLoader loader;
MySQLBulkLoaderData ld = new MySQLBulkLoaderData();
MySQLBulkLoaderMeta lm = new MySQLBulkLoaderMeta();
TransMeta transMeta = new TransMeta();
transMeta.setName("loader");
PluginRegistry plugReg = PluginRegistry.getInstance();
String loaderPid = plugReg.getPluginId(StepPluginType.class, lm);
StepMeta stepMeta = new StepMeta(loaderPid, "loader", lm);
Trans trans = new Trans(transMeta);
transMeta.addStep(stepMeta);
trans.setRunning(true);
loader = Mockito.spy(new MySQLBulkLoader(stepMeta, ld, 1, transMeta, trans));
RowMeta rm = new RowMeta();
ValueMetaNumber vm = new ValueMetaNumber("Test");
rm.addValueMeta(vm);
RowMeta spyRowMeta = Mockito.spy(new RowMeta());
Mockito.when(spyRowMeta.getValueMeta(Mockito.anyInt())).thenReturn(vm);
loader.setInputRowMeta(spyRowMeta);
MySQLBulkLoaderMeta smi = new MySQLBulkLoaderMeta();
smi.setFieldStream(new String[] { "Test" });
smi.setFieldFormatType(new int[] { MySQLBulkLoaderMeta.FIELD_FORMAT_TYPE_OK });
smi.setDatabaseMeta(Mockito.mock(DatabaseMeta.class));
ValueMetaNumber vmn = new ValueMetaNumber("Test");
vmn.setLength(6, 3);
MySQLBulkLoaderData sdi = new MySQLBulkLoaderData();
sdi.keynrs = new int[1];
sdi.keynrs[0] = 0;
sdi.fifoStream = Mockito.mock(OutputStream.class);
sdi.bulkFormatMeta = new ValueMetaInterface[] { vmn };
loader.init(smi, sdi);
loader.first = false;
Mockito.when(loader.getRow()).thenReturn(new Double[] { 1.023 });
loader.processRow(smi, sdi);
Mockito.verify(sdi.fifoStream, Mockito.times(1)).write(" 001.023".getBytes());
Assert.assertEquals(" #000.000;-#000.000", vmn.getDecimalFormat().toPattern());
}
use of org.pentaho.di.core.row.value.ValueMetaNumber in project pentaho-kettle by pentaho.
the class JsonInputTest method testSmallDoubles.
@Test
public void testSmallDoubles() throws Exception {
// legacy parser handles these but positive exp would read null
for (String nbr : new String[] { "1e-20", "1.52999996e-20", "2.05E-20" }) {
final String ibgNbrInput = "{ \"number\": " + nbr + " }";
testSimpleJsonPath("$.number", new ValueMetaNumber("not so big number"), new Object[][] { new Object[] { ibgNbrInput } }, new Object[][] { new Object[] { ibgNbrInput, Double.parseDouble(nbr) } });
}
}
Aggregations