Search in sources :

Example 76 with RowSet

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);
}
Also used : RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString)

Example 77 with RowSet

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]);
    }
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) Test(org.junit.Test)

Example 78 with RowSet

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());
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Test(org.junit.Test)

Example 79 with RowSet

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));
}
Also used : Arrays(java.util.Arrays) Trans(org.pentaho.di.trans.Trans) RowSet(org.pentaho.di.core.RowSet) StepDataInterface(org.pentaho.di.trans.step.StepDataInterface) RowMeta(org.pentaho.di.core.row.RowMeta) Mockito.spy(org.mockito.Mockito.spy) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TransMeta(org.pentaho.di.trans.TransMeta) After(org.junit.After) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Matchers.any(org.mockito.Matchers.any) StepMockHelper(org.pentaho.di.trans.steps.mock.StepMockHelper) List(java.util.List) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) KettleStepException(org.pentaho.di.core.exception.KettleStepException) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) Assert(org.junit.Assert) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) Mockito.mock(org.mockito.Mockito.mock) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 80 with RowSet

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));
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) ArrayList(java.util.ArrayList) StepIOMetaInterface(org.pentaho.di.trans.step.StepIOMetaInterface) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) StreamInterface(org.pentaho.di.trans.step.errorhandling.StreamInterface) Test(org.junit.Test)

Aggregations

RowSet (org.pentaho.di.core.RowSet)109 Test (org.junit.Test)43 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)40 RowMeta (org.pentaho.di.core.row.RowMeta)34 QueueRowSet (org.pentaho.di.core.QueueRowSet)26 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)25 KettleException (org.pentaho.di.core.exception.KettleException)23 BlockingRowSet (org.pentaho.di.core.BlockingRowSet)21 KettleStepException (org.pentaho.di.core.exception.KettleStepException)19 ArrayList (java.util.ArrayList)16 StepInterface (org.pentaho.di.trans.step.StepInterface)13 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)12 StepMeta (org.pentaho.di.trans.step.StepMeta)11 SingleRowRowSet (org.pentaho.di.core.SingleRowRowSet)10 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)9 RowAdapter (org.pentaho.di.trans.step.RowAdapter)9 Matchers.anyString (org.mockito.Matchers.anyString)7 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)7 IOException (java.io.IOException)6 ValueMetaNumber (org.pentaho.di.core.row.value.ValueMetaNumber)6