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;
}
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);
}
}
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);
}
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();
}
}
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;
}
Aggregations