Search in sources :

Example 36 with ValueMetaInteger

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

the class SelectValuesTest method testPDI16368.

@Test
public void testPDI16368() throws Exception {
    // This tests that the fix for PDI-16388 doesn't get re-broken.
    // 
    SelectValuesHandler step2 = null;
    Object[] inputRow2 = null;
    RowMeta inputRowMeta = null;
    SelectValuesMeta stepMeta = null;
    SelectValuesData stepData = null;
    ValueMetaInterface vmi = null;
    // First, test current behavior (it's worked this way since 5.x or so)
    // 
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2 = spy(step2);
    // Starting with a BigDecimal (no places)
    inputRow2 = new Object[] { new BigDecimal("589") };
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
    null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2 = spy(step2);
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
    null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2 = spy(step2);
    // Starting with a Long
    inputRow2 = new Object[] { new Long("589") };
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    // no specified conversion type so should have default conversion mask for BigNumber
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
    // Now, test that setting the variable results in getting the default conversion mask
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
    step2 = spy(step2);
    // Starting with a BigDecimal (no places)
    inputRow2 = new Object[] { new BigDecimal("589") };
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_INTEGER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask.
    null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_INTEGER_FORMAT_MASK, vmi.getConversionMask());
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
    step2 = spy(step2);
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaBigNumber(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_NUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, // no specified conversion type so should have default conversion mask for Double.
    null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_NUMBER_FORMAT_MASK, vmi.getConversionMask());
    step2 = new SelectValuesHandler(helper.stepMeta, helper.stepDataInterface, 1, helper.transMeta, helper.trans);
    step2.setVariable(Const.KETTLE_COMPATIBILITY_SELECT_VALUES_TYPE_CHANGE_USES_TYPE_DEFAULTS, "Y");
    step2 = spy(step2);
    // Starting with a Long
    inputRow2 = new Object[] { new Long("589") };
    doReturn(inputRow2).when(step2).getRow();
    doNothing().when(step2).putError(any(RowMetaInterface.class), any(Object[].class), anyLong(), anyString(), anyString(), anyString());
    inputRowMeta = new RowMeta();
    inputRowMeta.addValueMeta(new ValueMetaInteger(SELECTED_FIELD));
    step2.setInputRowMeta(inputRowMeta);
    stepMeta = new SelectValuesMeta();
    stepMeta.allocate(1, 0, 1);
    stepMeta.getSelectFields()[0] = new SelectField();
    stepMeta.getSelectFields()[0].setName(SELECTED_FIELD);
    // no specified conversion type so should have default conversion mask for BigNumber
    stepMeta.getMeta()[0] = new SelectMetadataChange(stepMeta, SELECTED_FIELD, null, ValueMetaInterface.TYPE_BIGNUMBER, -2, -2, ValueMetaInterface.STORAGE_TYPE_NORMAL, null, false, null, null, false, null, null, null);
    stepData = new SelectValuesData();
    stepData.select = true;
    stepData.metadata = true;
    stepData.firstselect = true;
    stepData.firstmetadata = true;
    step2.processRow(stepMeta, stepData);
    vmi = step2.rowMeta.getValueMeta(0);
    assertEquals(ValueMetaBase.DEFAULT_BIG_NUMBER_FORMAT_MASK, vmi.getConversionMask());
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) SelectField(org.pentaho.di.trans.steps.selectvalues.SelectValuesMeta.SelectField) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) BigDecimal(java.math.BigDecimal) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaBigNumber(org.pentaho.di.core.row.value.ValueMetaBigNumber) Matchers.anyLong(org.mockito.Matchers.anyLong) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Test(org.junit.Test)

Example 37 with ValueMetaInteger

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

the class RowSetTest method createRowMetaInterface.

public RowMetaInterface createRowMetaInterface() {
    RowMetaInterface rm = new RowMeta();
    ValueMetaInterface[] valuesMeta = { new ValueMetaInteger("ROWNR") };
    for (int i = 0; i < valuesMeta.length; i++) {
        rm.addValueMeta(valuesMeta[i]);
    }
    return rm;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface)

Example 38 with ValueMetaInteger

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

the class ConditionTest method testNullLessThanNumberEvaluatesAsFalse.

@Test
public void testNullLessThanNumberEvaluatesAsFalse() throws Exception {
    RowMetaInterface rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(new ValueMetaInteger("name1"));
    String left = "name1";
    ValueMetaAndData right_exact = new ValueMetaAndData(new ValueMetaInteger("name1"), new Long(-10));
    Condition condition = new Condition(left, Condition.FUNC_SMALLER, null, right_exact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
    condition = new Condition(left, Condition.FUNC_SMALLER_EQUAL, null, right_exact);
    assertFalse(condition.evaluate(rowMeta1, new Object[] { null, "test" }));
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaAndData(org.pentaho.di.core.row.ValueMetaAndData) Test(org.junit.Test)

Example 39 with ValueMetaInteger

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

the class RowMetaAndDataTest method prepare.

@Before
public void prepare() throws Exception {
    rowsMeta = new RowMeta();
    ValueMetaInterface valueMetaString = new ValueMetaString("str");
    rowsMeta.addValueMeta(valueMetaString);
    ValueMetaInterface valueMetaBoolean = new ValueMetaBoolean("bool");
    rowsMeta.addValueMeta(valueMetaBoolean);
    ValueMetaInterface valueMetaInteger = new ValueMetaInteger("int");
    rowsMeta.addValueMeta(valueMetaInteger);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Before(org.junit.Before)

Example 40 with ValueMetaInteger

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

the class RowMetaAndDataTest method testEmptyValues.

@Test
public void testEmptyValues() throws Exception {
    RowMeta rowsMetaEmpty = new RowMeta();
    rowsMetaEmpty.addValueMeta(new ValueMetaString("str"));
    rowsMetaEmpty.addValueMeta(new ValueMetaBoolean("bool"));
    rowsMetaEmpty.addValueMeta(new ValueMetaInteger("int"));
    rowsMetaEmpty.addValueMeta(new ValueMetaNumber("num"));
    rowsMetaEmpty.addValueMeta(new ValueMetaBigNumber("bignum"));
    rowsMetaEmpty.addValueMeta(new ValueMetaBinary("bin"));
    rowsMetaEmpty.addValueMeta(new ValueMetaDate("date"));
    rowsMetaEmpty.addValueMeta(new ValueMetaTimestamp("timestamp"));
    rowsMetaEmpty.addValueMeta(new ValueMetaInternetAddress("inet"));
    row = new RowMetaAndData(rowsMetaEmpty, null, null, null, null, null, null, null, null, null);
    assertTrue(row.isEmptyValue("str"));
    assertTrue(row.isEmptyValue("bool"));
    assertTrue(row.isEmptyValue("int"));
    assertTrue(row.isEmptyValue("num"));
    assertTrue(row.isEmptyValue("bignum"));
    assertTrue(row.isEmptyValue("bin"));
    assertTrue(row.isEmptyValue("date"));
    assertTrue(row.isEmptyValue("timestamp"));
    assertTrue(row.isEmptyValue("inet"));
}
Also used : ValueMetaBinary(org.pentaho.di.core.row.value.ValueMetaBinary) ValueMetaTimestamp(org.pentaho.di.core.row.value.ValueMetaTimestamp) 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) ValueMetaInternetAddress(org.pentaho.di.core.row.value.ValueMetaInternetAddress) ValueMetaBoolean(org.pentaho.di.core.row.value.ValueMetaBoolean) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)314 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)209 RowMeta (org.pentaho.di.core.row.RowMeta)146 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)137 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)113 Test (org.junit.Test)90 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)64 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)61 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)57 KettleException (org.pentaho.di.core.exception.KettleException)41 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)34 ObjectId (org.pentaho.di.repository.ObjectId)33 ArrayList (java.util.ArrayList)32 KettleStepException (org.pentaho.di.core.exception.KettleStepException)26 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)21 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)20 ValueMetaBinary (org.pentaho.di.core.row.value.ValueMetaBinary)18 SQLException (java.sql.SQLException)17