use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class ExcelWriterStep_StyleFormatTest method setupStepMock.
/**
* Create ExcelWriterStep object and mock some of its required data
*
* @param fileType
* @throws Exception
*/
private void setupStepMock(String fileType) throws Exception {
step = new ExcelWriterStep(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
step.init(stepMockHelper.initStepMetaInterface, stepMockHelper.initStepDataInterface);
List<Object[]> rows = createRowData();
String[] outFields = new String[] { "col 1", "col 2", "col 3", "col 4" };
RowSet inputRowSet = stepMockHelper.getMockInputRowSet(rows);
RowMetaInterface inputRowMeta = createRowMeta();
inputRowSet.setRowMeta(inputRowMeta);
RowMetaInterface mockOutputRowMeta = mock(RowMetaInterface.class);
when(mockOutputRowMeta.size()).thenReturn(outFields.length);
when(inputRowSet.getRowMeta()).thenReturn(inputRowMeta);
step.addRowSetToInputRowSets(inputRowSet);
step.setInputRowMeta(inputRowMeta);
step.addRowSetToOutputRowSets(inputRowSet);
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class FieldSplitterTest method testSplitFields.
@Test
public void testSplitFields() throws KettleException {
FieldSplitter step = new FieldSplitter(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
step.init(smh.initStepMetaInterface, smh.stepDataInterface);
step.setInputRowMeta(getInputRowMeta());
step.addRowSetToInputRowSets(mockInputRowSet());
step.addRowSetToOutputRowSets(new QueueRowSet());
boolean hasMoreRows;
do {
hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
} while (hasMoreRows);
RowSet outputRowSet = step.getOutputRowSets().get(0);
Object[] actualRow = outputRowSet.getRow();
Object[] expectedRow = new Object[] { "before", null, "b=b", "after" };
assertEquals("Output row is of an unexpected length", expectedRow.length, outputRowSet.getRowMeta().size());
for (int i = 0; i < expectedRow.length; i++) {
assertEquals("Unexpected output value at index " + i, expectedRow[i], actualRow[i]);
}
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class FieldSplitterTest method testSplitFieldsDup.
@Test
public void testSplitFieldsDup() throws Exception {
FieldSplitterMeta meta = new FieldSplitterMeta();
meta.allocate(2);
meta.setDelimiter(" ");
meta.setEnclosure("");
meta.setSplitField("split");
meta.setFieldName(new String[] { "key", "val" });
meta.setFieldType(new int[] { ValueMetaInterface.TYPE_STRING, ValueMetaInterface.TYPE_STRING });
FieldSplitter step = new FieldSplitter(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
step.init(meta, smh.stepDataInterface);
RowMetaInterface rowMeta = new RowMeta();
rowMeta.addValueMeta(new ValueMetaString("key"));
rowMeta.addValueMeta(new ValueMetaString("val"));
rowMeta.addValueMeta(new ValueMetaString("split"));
step.setInputRowMeta(rowMeta);
step.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[] { "key", "string", "part1 part2" }));
step.addRowSetToOutputRowSets(new SingleRowRowSet());
assertTrue(step.processRow(meta, smh.stepDataInterface));
RowSet rs = step.getOutputRowSets().get(0);
Object[] row = rs.getRow();
RowMetaInterface rm = rs.getRowMeta();
assertArrayEquals(new Object[] { "key", "string", "part1", "part2" }, Arrays.copyOf(row, 4));
assertArrayEquals(new Object[] { "key", "val", "key_1", "val_1" }, rm.getFieldNames());
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class FuzzyMatchTest method testLookupValuesWhenMainFieldIsNull.
@Test
public void testLookupValuesWhenMainFieldIsNull() throws Exception {
FuzzyMatchData data = spy(new FuzzyMatchData());
FuzzyMatchMeta meta = spy(new FuzzyMatchMeta());
data.readLookupValues = false;
fuzzyMatch = new FuzzyMatchHandler(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
fuzzyMatch.init(meta, data);
fuzzyMatch.first = false;
data.indexOfMainField = 1;
Object[] inputRow = { "test input", null };
RowSet lookupRowSet = mockHelper.getMockInputRowSet(new Object[] { "test lookup" });
fuzzyMatch.addRowSetToInputRowSets(mockHelper.getMockInputRowSet(inputRow));
fuzzyMatch.addRowSetToInputRowSets(lookupRowSet);
fuzzyMatch.rowset = lookupRowSet;
RowMetaInterface rowMetaInterface = new RowMeta();
ValueMetaInterface valueMeta = new ValueMetaString("field1");
valueMeta.setStorageMetadata(new ValueMetaString("field1"));
valueMeta.setStorageType(ValueMetaInterface.TYPE_STRING);
rowMetaInterface.addValueMeta(valueMeta);
when(lookupRowSet.getRowMeta()).thenReturn(rowMetaInterface);
fuzzyMatch.setInputRowMeta(rowMetaInterface.clone());
data.outputRowMeta = rowMetaInterface.clone();
fuzzyMatch.processRow(meta, data);
Assert.assertEquals(inputRow[0], fuzzyMatch.resultRow[0]);
Assert.assertNull(fuzzyMatch.resultRow[1]);
Assert.assertTrue(Arrays.stream(fuzzyMatch.resultRow, 3, fuzzyMatch.resultRow.length).allMatch(val -> val == null));
}
use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.
the class FuzzyMatchTest method testReadLookupValues.
@Test
public void testReadLookupValues() throws Exception {
FuzzyMatchData data = spy(new FuzzyMatchData());
data.indexOfCachedFields = new int[2];
data.minimalDistance = 0;
data.maximalDistance = 5;
FuzzyMatchMeta meta = spy(new FuzzyMatchMeta());
meta.setOutputMatchField("I don't want NPE here!");
data.readLookupValues = true;
fuzzyMatch = new FuzzyMatchHandler(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
fuzzyMatch.init(meta, data);
RowSet lookupRowSet = mockHelper.getMockInputRowSet(binaryLookupRows);
fuzzyMatch.addRowSetToInputRowSets(mockHelper.getMockInputRowSet(binaryRows));
fuzzyMatch.addRowSetToInputRowSets(lookupRowSet);
fuzzyMatch.rowset = lookupRowSet;
RowMetaInterface rowMetaInterface = new RowMeta();
ValueMetaInterface valueMeta = new ValueMetaString("field1");
valueMeta.setStorageMetadata(new ValueMetaString("field1"));
valueMeta.setStorageType(ValueMetaInterface.STORAGE_TYPE_BINARY_STRING);
rowMetaInterface.addValueMeta(valueMeta);
when(lookupRowSet.getRowMeta()).thenReturn(rowMetaInterface);
when(meta.getLookupField()).thenReturn("field1");
when(meta.getMainStreamField()).thenReturn("field1");
fuzzyMatch.setInputRowMeta(rowMetaInterface.clone());
when(meta.getAlgorithmType()).thenReturn(1);
StepIOMetaInterface stepIOMetaInterface = mock(StepIOMetaInterface.class);
when(meta.getStepIOMeta()).thenReturn(stepIOMetaInterface);
StreamInterface streamInterface = mock(StreamInterface.class);
List<StreamInterface> streamInterfaceList = new ArrayList<StreamInterface>();
streamInterfaceList.add(streamInterface);
when(streamInterface.getStepMeta()).thenReturn(mockHelper.stepMeta);
when(stepIOMetaInterface.getInfoStreams()).thenReturn(streamInterfaceList);
fuzzyMatch.processRow(meta, data);
Assert.assertEquals(rowMetaInterface.getString(row3B, 0), data.outputRowMeta.getString(fuzzyMatch.resultRow, 1));
}
Aggregations