Search in sources :

Example 26 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class NullIfTest method testDateWithFormat.

@Test
public void testDateWithFormat() throws KettleException {
    KettleEnvironment.init();
    NullIf step = new NullIf(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    step.setInputRowMeta(getInputRowMeta2());
    Date d1 = null;
    Date d2 = null;
    Date d3 = null;
    Date d4 = null;
    try {
        DateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        d1 = formatter.parse("20150606");
        d3 = formatter.parse("20150607");
        formatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS");
        d2 = formatter.parse("2015/06/06 00:00:00.000");
        d4 = formatter.parse("2015/07/06 00:00:00.000");
    } catch (ParseException e) {
        e.printStackTrace();
    }
    step.addRowSetToInputRowSets(smh.getMockInputRowSet(new Object[][] { { d1, d2, d3, d4 } }));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta2(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    Object[] actualRow = outputRowSet.getRow();
    Object[] expectedRow = new Object[] { null, null, d3, d4 };
    Assert.assertEquals("Output row is of an unexpected length", expectedRow.length, outputRowSet.getRowMeta().size());
    for (int i = 0; i < expectedRow.length; i++) {
        Assert.assertEquals("Unexpected output value at index " + i, expectedRow[i], actualRow[i]);
    }
}
Also used : QueueRowSet(org.pentaho.di.core.QueueRowSet) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) ValueMetaDate(org.pentaho.di.core.row.value.ValueMetaDate) Test(org.junit.Test)

Example 27 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class GroupByTest method testProcessRow.

@Test
public void testProcessRow() throws KettleException {
    GroupByMeta groupByMeta = mock(GroupByMeta.class);
    GroupByData groupByData = mock(GroupByData.class);
    GroupBy groupBySpy = Mockito.spy(new GroupBy(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans));
    doReturn(null).when(groupBySpy).getRow();
    doReturn(null).when(groupBySpy).getInputRowMeta();
    RowMetaInterface rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaInteger("ROWNR"));
    List<RowSet> outputRowSets = new ArrayList<RowSet>();
    BlockingRowSet rowSet = new BlockingRowSet(1);
    rowSet.putRow(rowMeta, new Object[] { new Long(0) });
    outputRowSets.add(rowSet);
    groupBySpy.setOutputRowSets(outputRowSets);
    final String[] sub = { "b" };
    doReturn(sub).when(groupByMeta).getSubjectField();
    final String[] groupField = { "a" };
    doReturn(groupField).when(groupByMeta).getGroupField();
    final String[] aggFields = { "b_g" };
    doReturn(aggFields).when(groupByMeta).getAggregateField();
    final int[] aggType = { GroupByMeta.TYPE_GROUP_CONCAT_COMMA };
    doReturn(aggType).when(groupByMeta).getAggregateType();
    when(mockHelper.transMeta.getPrevStepFields(mockHelper.stepMeta)).thenReturn(new RowMeta());
    groupBySpy.processRow(groupByMeta, groupByData);
    assertTrue(groupBySpy.getOutputRowSets().get(0).isDone());
}
Also used : RowMeta(org.pentaho.di.core.row.RowMeta) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ArrayList(java.util.ArrayList) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) Matchers.anyString(org.mockito.Matchers.anyString) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Test(org.junit.Test)

Example 28 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class IfNullTest method testString_emptyIsNotNull.

@Test
public void testString_emptyIsNotNull() throws KettleException {
    // FieldAccessor.ensureEmptyStringIsNotNull( true );
    Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", true);
    IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    step.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "", "    ", "value5" };
    step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 29 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class IfNullTest method testString_emptyIsNull.

@Test
public void testString_emptyIsNull() throws KettleException {
    Whitebox.setInternalState(ValueMetaBase.class, "EMPTY_STRING_AND_NULL_ARE_DIFFERENT", false);
    IfNull step = new IfNull(smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans);
    step.init(smh.initStepMetaInterface, smh.stepDataInterface);
    final RowMeta inputRowMeta = buildInputRowMeta(// 
    new ValueMetaString("some-field"), // 
    new ValueMetaString("null-field"), // 
    new ValueMetaString("empty-field"), // 
    new ValueMetaString("space-field"), // 
    new ValueMetaString("another-field"));
    step.setInputRowMeta(inputRowMeta);
    final Object[] inputRow = new Object[] { "value1", null, "", "    ", "value5" };
    final Object[] expectedRow = new Object[] { "value1", "replace-value", "replace-value", "    ", "value5" };
    step.addRowSetToInputRowSets(buildInputRowSet(inputRow));
    step.addRowSetToOutputRowSets(new QueueRowSet());
    boolean hasMoreRows;
    do {
        hasMoreRows = step.processRow(mockProcessRowMeta(), smh.processRowsStepDataInterface);
    } while (hasMoreRows);
    RowSet outputRowSet = step.getOutputRowSets().get(0);
    assertRowSetMatches("", expectedRow, outputRowSet);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) QueueRowSet(org.pentaho.di.core.QueueRowSet) RowSet(org.pentaho.di.core.RowSet) QueueRowSet(org.pentaho.di.core.QueueRowSet) Test(org.junit.Test)

Example 30 with RowSet

use of org.pentaho.di.core.RowSet in project pentaho-kettle by pentaho.

the class JoinRowsTest method testJoinRowsStep.

@Test
public void testJoinRowsStep() throws Exception {
    JoinRowsMeta joinRowsMeta = new JoinRowsMeta();
    joinRowsMeta.setMainStepname("main step name");
    joinRowsMeta.setPrefix("out");
    joinRowsMeta.setCacheSize(3);
    JoinRowsData joinRowsData = new JoinRowsData();
    JoinRows joinRows = getJoinRows();
    joinRows.getTrans().setRunning(true);
    joinRows.init(joinRowsMeta, joinRowsData);
    List<RowSet> rowSets = new ArrayList<>();
    rowSets.add(getRowSetWithData(3, "main --", true));
    rowSets.add(getRowSetWithData(3, "secondary --", false));
    joinRows.setInputRowSets(rowSets);
    RowStepCollector rowStepCollector = new RowStepCollector();
    joinRows.addRowListener(rowStepCollector);
    joinRows.getLogChannel().setLogLevel(LogLevel.ROWLEVEL);
    KettleLogStore.init();
    while (true) {
        if (!joinRows.processRow(joinRowsMeta, joinRowsData)) {
            break;
        }
    }
    rowStepCollector.getRowsWritten();
    // since we have data join of two row sets with size 3 then we must have 9 written rows
    assertEquals(9, rowStepCollector.getRowsWritten().size());
    assertEquals(6, rowStepCollector.getRowsRead().size());
    Object[][] expectedResult = createExpectedResult();
    List<Object[]> rowWritten = rowStepCollector.getRowsWritten().stream().map(RowMetaAndData::getData).collect(Collectors.toList());
    for (int i = 0; i < 9; i++) {
        assertTrue(Arrays.equals(expectedResult[i], rowWritten.get(i)));
    }
}
Also used : RowStepCollector(org.pentaho.di.trans.RowStepCollector) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) ArrayList(java.util.ArrayList) 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