Search in sources :

Example 66 with ValueMetaNumber

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 }));
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 67 with ValueMetaNumber

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));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 68 with ValueMetaNumber

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));
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Test(org.junit.Test)

Example 69 with ValueMetaNumber

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());
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) OutputStream(java.io.OutputStream) TransMeta(org.pentaho.di.trans.TransMeta) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Trans(org.pentaho.di.trans.Trans) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) MySQLDatabaseMeta(org.pentaho.di.core.database.MySQLDatabaseMeta) Test(org.junit.Test)

Example 70 with ValueMetaNumber

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) } });
    }
}
Also used : ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) 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