use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MappingInputFieldsTest method testSelectingAndSortingUnspecifiedFields.
/**
* verifies: If SelectingAndSortingUnspecifiedFields checkbox is checked, then
* <ol>
* <li>all fields throw to the next step;
* <li>fields are resorted: mapped fields, then alphabetical sorted not mapped fields.
* </ol>
*/
@Test
public void testSelectingAndSortingUnspecifiedFields() throws Exception {
meta.setSelectingAndSortingUnspecifiedFields(true);
MappingInputData sdi = new MappingInputData();
sdi.linked = true;
sdi.valueRenames = new ArrayList<MappingValueRename>();
sdi.valueRenames.add(new MappingValueRename("number2", "n2"));
sdi.valueRenames.add(new MappingValueRename("number4", "n4"));
BlockingRowSet in = new BlockingRowSet(10);
BlockingRowSet out = new BlockingRowSet(10);
RowMeta rm = new RowMeta();
rm.addValueMeta(new ValueMetaString("string"));
rm.addValueMeta(new ValueMetaInteger("number1"));
rm.addValueMeta(new ValueMetaInteger("number2"));
rm.addValueMeta(new ValueMetaInteger("number3"));
rm.addValueMeta(new ValueMetaInteger("number"));
rm.addValueMeta(new ValueMetaInteger("number4"));
rm.addValueMeta(new ValueMetaInteger("number5"));
in.putRow(rm, new Object[] { "str", new Integer(100501), new Integer(100502), new Integer(100503), new Integer(100500), new Integer(100504), new Integer(100505) });
in.putRow(rm, new Object[] { "str_1", new Integer(200501), new Integer(200502), new Integer(200503), new Integer(200500), new Integer(200504), new Integer(200505) });
step.addRowSetToInputRowSets(in);
step.addRowSetToOutputRowSets(out);
assertTrue(step.init(meta, sdi));
assertTrue(step.processRow(meta, sdi));
Object[] outRowData = out.getRow();
RowMetaInterface outMeta = out.getRowMeta();
assertEquals("All fields are expected.", 7, outMeta.size());
int i = 0;
// Check if row-meta is formed according to the step specification
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
// Check if row-data corresponds to the row-meta
assertEquals("the field value mismatch.", new Integer(100502), outRowData[0]);
assertEquals("the field value mismatch.", new Integer(100504), outRowData[1]);
assertEquals("the field value mismatch.", new Integer(100500), outRowData[2]);
assertEquals("the field value mismatch.", new Integer(100501), outRowData[3]);
assertEquals("the field value mismatch.", new Integer(100503), outRowData[4]);
assertEquals("the field value mismatch.", new Integer(100505), outRowData[5]);
assertEquals("the field value mismatch.", "str", outRowData[6]);
assertTrue(step.processRow(meta, sdi));
outRowData = out.getRow();
outMeta = out.getRowMeta();
assertEquals("All fields are expected.", 7, outMeta.size());
i = 0;
// Check if row-meta is formed according to the step specification
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n2", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "n4", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number1", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number3", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_INTEGER, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "number5", outMeta.getValueMeta(i++).getName());
assertEquals("the field type-meta mismatch.", ValueMetaInterface.TYPE_STRING, outMeta.getValueMeta(i).getType());
assertEquals("the field name-meta mismatch.", "string", outMeta.getValueMeta(i++).getName());
// Check if row-data corresponds to the row-meta
assertEquals("the field value mismatch.", new Integer(200502), outRowData[0]);
assertEquals("the field value mismatch.", new Integer(200504), outRowData[1]);
assertEquals("the field value mismatch.", new Integer(200500), outRowData[2]);
assertEquals("the field value mismatch.", new Integer(200501), outRowData[3]);
assertEquals("the field value mismatch.", new Integer(200503), outRowData[4]);
assertEquals("the field value mismatch.", new Integer(200505), outRowData[5]);
assertEquals("the field value mismatch.", "str_1", outRowData[6]);
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MemoryGroupByAggregationTest method testNullsAreZeroDefault.
@Test
public void testNullsAreZeroDefault() throws Exception {
variables.setVariable(Const.KETTLE_AGGREGATION_ALL_NULLS_ARE_ZERO, "Y");
addColumn(new ValueMetaInteger("nul"));
addColumn(new ValueMetaInteger("both"), -2L, 0L, null, 10L);
addColumn(new ValueMetaNumber("both_num"), -2.0, 0.0, null, 10.0);
RowMetaAndData output = runStep();
assertThat(output.getInteger("nul_min"), is(0L));
assertThat(output.getInteger("nul_max"), is(0L));
assertThat(output.getInteger("nul_sum"), is(0L));
assertThat(output.getInteger("nul_ave"), is(0L));
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("both_max"), is(10L));
assertThat(output.getInteger("both_min"), is(-2L));
assertThat(output.getInteger("both_sum"), is(8L));
assertThat(output.getInteger("both_ave"), is(2L));
assertThat(output.getInteger("both_count"), is(3L));
assertThat(output.getInteger("both_count_any"), is(4L));
assertThat(output.getInteger("both_count_distinct"), is(3L));
assertThat(output.getNumber("both_num_max", Double.NaN), is(10.0));
assertThat(output.getNumber("both_num_min", Double.NaN), is(-2.0));
assertThat(output.getNumber("both_num_sum", Double.NaN), is(8.0));
assertEquals(2.666666, output.getNumber("both_num_ave", Double.NaN), 0.000001);
assertThat(output.getInteger("both_num_count"), is(3L));
assertThat(output.getInteger("both_num_count_any"), is(4L));
assertThat(output.getInteger("both_num_count_distinct"), is(3L));
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MemoryGroupByMetaTest method getInputRowMeta.
private RowMetaInterface getInputRowMeta() {
RowMetaInterface rm = new RowMeta();
rm.addValueMeta(new ValueMetaString("myGroupField2"));
rm.addValueMeta(new ValueMetaString("myGroupField1"));
rm.addValueMeta(new ValueMetaString("myString"));
rm.addValueMeta(new ValueMetaInteger("myInteger"));
rm.addValueMeta(new ValueMetaNumber("myNumber"));
rm.addValueMeta(new ValueMetaBigNumber("myBigNumber"));
rm.addValueMeta(new ValueMetaBinary("myBinary"));
rm.addValueMeta(new ValueMetaBoolean("myBoolean"));
rm.addValueMeta(new ValueMetaDate("myDate"));
rm.addValueMeta(new ValueMetaTimestamp("myTimestamp"));
rm.addValueMeta(new ValueMetaInternetAddress("myInternetAddress"));
return rm;
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MemoryGroupByNewAggregateTest method setUp.
@Before
public void setUp() throws Exception {
data = new MemoryGroupByData();
data.subjectnrs = new int[16];
int[] arr = new int[16];
String[] arrF = new String[16];
for (int i = 0; i < arr.length; i++) {
// set aggregation types (hardcoded integer values from 1 to 18)
arr[i] = i + 1;
data.subjectnrs[i] = i;
}
Arrays.fill(arrF, "x");
MemoryGroupByMeta meta = new MemoryGroupByMeta();
meta.setAggregateType(arr);
meta.setAggregateField(arrF);
ValueMetaInterface vmi = new ValueMetaInteger();
when(mockHelper.stepMeta.getStepMetaInterface()).thenReturn(meta);
RowMetaInterface rmi = Mockito.mock(RowMetaInterface.class);
data.inputRowMeta = rmi;
when(rmi.getValueMeta(Mockito.anyInt())).thenReturn(vmi);
data.aggMeta = rmi;
step = new MemoryGroupBy(mockHelper.stepMeta, data, 0, mockHelper.transMeta, mockHelper.trans);
}
use of org.pentaho.di.core.row.value.ValueMetaInteger in project pentaho-kettle by pentaho.
the class MergeJoinMetaTest method testGetFieldsEmptyInput.
@Test
public void testGetFieldsEmptyInput() throws Exception {
RowMeta outputRowMeta = new RowMeta();
MergeJoinMeta meta = new MergeJoinMeta();
RowMeta inputRow1 = new RowMeta();
ValueMetaInteger field1_row1 = new ValueMetaInteger("field1");
field1_row1.setOrigin("inputStep1");
inputRow1.addValueMeta(field1_row1);
ValueMetaString field2_row1 = new ValueMetaString("field2");
field2_row1.setOrigin("inputStep1");
inputRow1.addValueMeta(field2_row1);
RowMeta inputRow2 = new RowMeta();
ValueMetaString field1_row2 = new ValueMetaString("field1");
field1_row2.setOrigin("inputStep2");
inputRow2.addValueMeta(field1_row2);
ValueMetaString field3_row2 = new ValueMetaString("field3");
field3_row2.setOrigin("inputStep2");
inputRow2.addValueMeta(field3_row2);
StepMeta stepMeta = new StepMeta("Merge", meta);
meta.getFields(outputRowMeta, "Merge Join", new RowMetaInterface[] { inputRow1, inputRow2 }, stepMeta, new Variables(), null, null);
assertNotNull(outputRowMeta);
assertFalse(outputRowMeta.isEmpty());
assertEquals(4, outputRowMeta.size());
List<ValueMetaInterface> vmi = outputRowMeta.getValueMetaList();
assertNotNull(vmi);
// Proceed in order
ValueMetaInterface field1 = outputRowMeta.getValueMeta(0);
assertNotNull(field1);
assertEquals("field1", field1.getName());
assertTrue(field1 instanceof ValueMetaInteger);
assertEquals("inputStep1", field1.getOrigin());
ValueMetaInterface field2 = outputRowMeta.getValueMeta(1);
assertNotNull(field2);
assertEquals("field2", field2.getName());
assertTrue(field2 instanceof ValueMetaString);
assertEquals("inputStep1", field2.getOrigin());
ValueMetaInterface field1_1 = outputRowMeta.getValueMeta(2);
assertNotNull(field1_1);
assertEquals("field1_1", field1_1.getName());
assertTrue(field1_1 instanceof ValueMetaString);
assertEquals("Merge Join", field1_1.getOrigin());
ValueMetaInterface field3 = outputRowMeta.getValueMeta(3);
assertNotNull(field3);
assertEquals("field3", field3.getName());
assertTrue(field3 instanceof ValueMetaString);
assertEquals("inputStep2", field3.getOrigin());
}
Aggregations