Search in sources :

Example 76 with ValueMetaInteger

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

the class DenormaliserAggregationsTest method testSumPreconditions.

/**
 * This is extracted common part for sum tests
 *
 * @return
 */
RowMetaInterface testSumPreconditions(String agg) {
    // create rmi for one string and 2 integers
    RowMetaInterface rmi = new RowMeta();
    List<ValueMetaInterface> list = new ArrayList<ValueMetaInterface>();
    list.add(new ValueMetaString("a"));
    list.add(new ValueMetaInteger("b"));
    list.add(new ValueMetaInteger("d"));
    rmi.setValueMetaList(list);
    // denormalizer key field will be String 'Junit'
    data.keyValue = new HashMap<String, List<Integer>>();
    List<Integer> listInt = new ArrayList<Integer>();
    listInt.add(0);
    data.keyValue.put(JUNIT, listInt);
    // we will calculate sum for second field ( like ["JUNIT", 1] )
    data.fieldNameIndex = new int[] { 1 };
    data.inputRowMeta = rmi;
    data.outputRowMeta = rmi;
    data.removeNrs = new int[] { -1 };
    // we do create internal instance of output field wiht sum aggregation
    DenormaliserTargetField tField = new DenormaliserTargetField();
    tField.setTargetAggregationType(agg);
    DenormaliserTargetField[] pivotField = new DenormaliserTargetField[] { tField };
    meta.setDenormaliserTargetField(pivotField);
    // return row meta interface to pass into denormalize method
    return rmi;
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ArrayList(java.util.ArrayList) List(java.util.List)

Example 77 with ValueMetaInteger

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

the class PDI4910_DenormaliserTest method testDeNormalise.

@Test
public void testDeNormalise() throws Exception {
    // init step data
    DenormaliserData stepData = new DenormaliserData();
    stepData.keyFieldNr = 0;
    stepData.keyValue = new HashMap<String, List<Integer>>();
    stepData.keyValue.put("1", Arrays.asList(new Integer[] { 0, 1 }));
    stepData.fieldNameIndex = new int[] { 1, 2 };
    stepData.inputRowMeta = new RowMeta();
    ValueMetaDate outDateField1 = new ValueMetaDate("date_field[yyyy-MM-dd]");
    ValueMetaDate outDateField2 = new ValueMetaDate("date_field[yyyy/MM/dd]");
    stepData.outputRowMeta = new RowMeta();
    stepData.outputRowMeta.addValueMeta(0, outDateField1);
    stepData.outputRowMeta.addValueMeta(1, outDateField2);
    stepData.removeNrs = new int[] {};
    stepData.targetResult = new Object[] { null, null };
    // init step meta
    DenormaliserMeta stepMeta = new DenormaliserMeta();
    DenormaliserTargetField[] denormaliserTargetFields = new DenormaliserTargetField[2];
    DenormaliserTargetField targetField1 = new DenormaliserTargetField();
    DenormaliserTargetField targetField2 = new DenormaliserTargetField();
    targetField1.setTargetFormat("yyyy-MM-dd");
    targetField2.setTargetFormat("yyyy/MM/dd");
    denormaliserTargetFields[0] = targetField1;
    denormaliserTargetFields[1] = targetField2;
    stepMeta.setDenormaliserTargetField(denormaliserTargetFields);
    // init row meta
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(0, new ValueMetaInteger("key"));
    rowMeta.addValueMeta(1, new ValueMetaString("stringDate1"));
    rowMeta.addValueMeta(2, new ValueMetaString("stringDate2"));
    // init row data
    Object[] rowData = new Object[] { 1L, "2000-10-20", "2000/10/20" };
    // init step
    denormaliser = new Denormaliser(mockHelper.stepMeta, stepData, 0, mockHelper.transMeta, mockHelper.trans);
    // inject step meta
    Field metaField = denormaliser.getClass().getDeclaredField("meta");
    Assert.assertNotNull("Can't find a field 'meta' in class Denormalizer", metaField);
    metaField.setAccessible(true);
    metaField.set(denormaliser, stepMeta);
    // call tested method
    Method deNormalise = denormaliser.getClass().getDeclaredMethod("deNormalise", RowMetaInterface.class, Object[].class);
    Assert.assertNotNull("Can't find a method 'deNormalise' in class Denormalizer", deNormalise);
    deNormalise.setAccessible(true);
    deNormalise.invoke(denormaliser, rowMeta, rowData);
    // vefiry
    for (Object res : stepData.targetResult) {
        Assert.assertNotNull("Date is null", res);
    }
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Method(java.lang.reflect.Method) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Field(java.lang.reflect.Field) List(java.util.List) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 78 with ValueMetaInteger

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

the class BaseStepTest method outputRowMetasAreNotSharedAmongSeveralStreams.

@Test
public void outputRowMetasAreNotSharedAmongSeveralStreams() throws Exception {
    RowSet rs1 = new SingleRowRowSet();
    RowSet rs2 = new SingleRowRowSet();
    when(mockHelper.trans.isRunning()).thenReturn(true);
    BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    baseStep.setStopped(false);
    baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_NONE);
    baseStep.setOutputRowSets(Arrays.asList(rs1, rs2));
    for (RowSet rowSet : baseStep.getOutputRowSets()) {
        assertNull("RowMeta should be null, since no calls were done", rowSet.getRowMeta());
    }
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("string"));
    rowMeta.addValueMeta(new ValueMetaInteger("integer"));
    baseStep.putRow(rowMeta, new Object[] { "a", 1 });
    RowMetaInterface meta1 = rs1.getRowMeta();
    RowMetaInterface meta2 = rs2.getRowMeta();
    assertNotNull(meta1);
    assertNotNull(meta2);
    // content is same
    for (ValueMetaInterface meta : meta1.getValueMetaList()) {
        assertTrue(meta.getName(), meta2.exists(meta));
    }
    // whereas instances differ
    assertFalse(meta1 == meta2);
}
Also used : SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 79 with ValueMetaInteger

use of org.pentaho.di.core.row.value.ValueMetaInteger 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();
    }
}
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) ValueMetaNumber(org.pentaho.di.core.row.value.ValueMetaNumber) RowAdapter(org.pentaho.di.trans.step.RowAdapter) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Example 80 with ValueMetaInteger

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

the class DatabaseLookupUTest method createSpiedStep.

private DatabaseLookup createSpiedStep(Database db, StepMockHelper<DatabaseLookupMeta, DatabaseLookupData> mockHelper, DatabaseLookupMeta meta) throws KettleException {
    DatabaseLookup step = spyLookup(mockHelper, db, meta.getDatabaseMeta());
    doNothing().when(step).determineFieldsTypesQueryingDb();
    doReturn(null).when(step).lookupValues(any(RowMetaInterface.class), any(Object[].class));
    RowMeta input = new RowMeta();
    input.addValueMeta(new ValueMetaInteger("Test"));
    step.setInputRowMeta(input);
    return step;
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Aggregations

ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)291 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)198 RowMeta (org.pentaho.di.core.row.RowMeta)132 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)124 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)110 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)89 Test (org.junit.Test)72 ValueMetaDate (org.pentaho.di.core.row.value.ValueMetaDate)63 ValueMetaBoolean (org.pentaho.di.core.row.value.ValueMetaBoolean)60 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)52 KettleException (org.pentaho.di.core.exception.KettleException)39 LongObjectId (org.pentaho.di.repository.LongObjectId)38 ObjectId (org.pentaho.di.repository.ObjectId)33 ValueMetaBigNumber (org.pentaho.di.core.row.value.ValueMetaBigNumber)31 KettleStepException (org.pentaho.di.core.exception.KettleStepException)25 ArrayList (java.util.ArrayList)21 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)20 ValueMetaTimestamp (org.pentaho.di.core.row.value.ValueMetaTimestamp)19 Date (java.util.Date)17 SQLException (java.sql.SQLException)16