Search in sources :

Example 71 with RowSet

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

the class TransPartitioningTest method testDifferentPartitioningFlow.

/**
 * This is PDI-12140 case. 2 steps with same partitions ID's count but different partitioner. This is not a swim lines
 * cases and we need repartitioning here.
 *
 * @throws KettleException
 */
@Test
public void testDifferentPartitioningFlow() throws KettleException {
    prepareStepMetas_cl1_cl2();
    trans.prepareExecution(new String[] {});
    List<RowSet> rowsets = trans.getRowsets();
    assertTrue(!rowsets.isEmpty());
    assertEquals("We have 4 rowsets finally since repartitioning happens", 4, rowsets.size());
    assertEquals("We have 4 steps: 2 producer copies and 2 copies of consumer since they both partitioned", 4, trans.getSteps().size());
    // Ok, examine initialized steps now.
    StepInterface stepOne0 = getStepByName(SP10);
    assertTrue("1.0 step have no input row sets", stepOne0.getInputRowSets().isEmpty());
    assertEquals("1.0 step have 2 output rowsets", 2, stepOne0.getOutputRowSets().size());
    StepInterface stepOne1 = getStepByName(SP11);
    assertTrue("1.1 step have no input row sets", stepOne1.getInputRowSets().isEmpty());
    assertEquals("1.1 step have 2 output rowsets", 2, stepOne1.getOutputRowSets().size());
    StepInterface stepTwo0 = getStepByName(SP20);
    assertTrue("2.0 step have no output row sets", stepTwo0.getOutputRowSets().isEmpty());
    assertEquals("2.0 step have 1 input rowsets", 2, stepTwo0.getInputRowSets().size());
    StepInterface stepTwo2 = getStepByName(SP21);
    assertTrue("2.1 step have no output row sets", stepTwo2.getOutputRowSets().isEmpty());
    assertEquals("2.2 step have 2 input rowsets", 2, stepTwo2.getInputRowSets().size());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowSet(org.pentaho.di.core.RowSet) Test(org.junit.Test)

Example 72 with RowSet

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

the class TransPartitioningTest method testSwimLanesPartitioning.

/**
 * Test 'Swim lines partitioning'
 *
 * @throws KettleException
 */
@Test
public void testSwimLanesPartitioning() throws KettleException {
    prepareStepMetas_cl1_cl1();
    trans.prepareExecution(new String[] {});
    List<RowSet> rowsets = trans.getRowsets();
    assertTrue(!rowsets.isEmpty());
    assertEquals("We have 2 rowsets finally", 2, rowsets.size());
    assertEquals("We have 3 steps: 1 producer and 2 copies of consumer since it is partitioned", 4, trans.getSteps().size());
    // Ok, examine initialized steps now.
    StepInterface stepOne0 = getStepByName(SP10);
    assertTrue("1.0 step have no input row sets", stepOne0.getInputRowSets().isEmpty());
    assertEquals("1.0 step have 1 output rowsets", 1, stepOne0.getOutputRowSets().size());
    StepInterface stepOne1 = getStepByName(SP11);
    assertTrue("1.1 step have no input row sets", stepOne1.getInputRowSets().isEmpty());
    assertEquals("1.1 step have 1 output rowsets", 1, stepOne1.getOutputRowSets().size());
    StepInterface stepTwo0 = getStepByName(SP20);
    assertEquals("2.0 step have 2 input row sets", 1, stepTwo0.getInputRowSets().size());
    assertTrue("2.0 step have no output rowsets", stepTwo0.getOutputRowSets().isEmpty());
    StepInterface stepTwo2 = getStepByName(SP21);
    assertTrue("2.2 step have no output row sets", stepTwo2.getOutputRowSets().isEmpty());
    assertEquals("2.2 step have 2 output rowsets", 1, stepTwo2.getInputRowSets().size());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowSet(org.pentaho.di.core.RowSet) Test(org.junit.Test)

Example 73 with RowSet

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

the class TransPartitioningTest method testManyToOneCopies.

/**
 * This checks transformation initialization when using many copies to one next step
 *
 * @throws KettleException
 */
@Test
public void testManyToOneCopies() throws KettleException {
    prepareStepMetas_x2_1();
    trans.prepareExecution(new String[] {});
    List<RowSet> rowsets = trans.getRowsets();
    assertTrue(!rowsets.isEmpty());
    assertEquals("We have 2 rowsets finally", 2, rowsets.size());
    assertEquals("We have 4 steps: 2 copies of producer and 2 copies of consumer", 3, trans.getSteps().size());
    // Ok, examine initialized steps now.
    StepInterface stepOne0 = getStepByName(S10);
    assertTrue("1 step have no input row sets", stepOne0.getInputRowSets().isEmpty());
    assertEquals("1 step have 1 output rowsets", 1, stepOne0.getOutputRowSets().size());
    StepInterface stepOne1 = getStepByName(S11);
    assertTrue("1 step have no input row sets", stepOne1.getInputRowSets().isEmpty());
    assertEquals("1 step have 1 output rowsets", 1, stepOne1.getOutputRowSets().size());
    StepInterface stepTwo0 = getStepByName(S20);
    Assert.assertEquals("2.0 step have 2 input row sets", 2, stepTwo0.getInputRowSets().size());
    Assert.assertTrue("2.0 step have no output row sets", stepTwo0.getOutputRowSets().isEmpty());
}
Also used : StepInterface(org.pentaho.di.trans.step.StepInterface) RowSet(org.pentaho.di.core.RowSet) Test(org.junit.Test)

Example 74 with RowSet

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

the class BaseStepTest method testBaseStepPutRowLocalSpecialPartitioning.

/**
 * This test checks that data from one non-partitioned step copies to 2 partitioned steps right.
 *
 * @throws KettleException
 * @see {@link <a href="http://jira.pentaho.com/browse/PDI-12211">http://jira.pentaho.com/browse/PDI-12211<a>}
 */
@Test
public void testBaseStepPutRowLocalSpecialPartitioning() throws KettleException {
    List<StepMeta> stepMetas = new ArrayList<StepMeta>();
    stepMetas.add(mockHelper.stepMeta);
    stepMetas.add(mockHelper.stepMeta);
    StepPartitioningMeta stepPartitioningMeta = spy(new StepPartitioningMeta());
    BasePartitioner partitioner = mock(BasePartitioner.class);
    when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenAnswer(new Answer<LogChannelInterface>() {

        @Override
        public LogChannelInterface answer(InvocationOnMock invocation) throws Throwable {
            ((BaseStep) invocation.getArguments()[0]).getLogLevel();
            return mockHelper.logChannelInterface;
        }
    });
    when(mockHelper.trans.isRunning()).thenReturn(true);
    when(mockHelper.transMeta.findNextSteps(any(StepMeta.class))).thenReturn(stepMetas);
    when(mockHelper.stepMeta.getStepPartitioningMeta()).thenReturn(stepPartitioningMeta);
    when(stepPartitioningMeta.getPartitioner()).thenReturn(partitioner);
    when(partitioner.getNrPartitions()).thenReturn(2);
    Object object0 = "name0";
    ValueMetaInterface meta0 = new ValueMetaString(object0.toString());
    Object object1 = "name1";
    ValueMetaInterface meta2 = new ValueMetaString(object1.toString());
    RowMetaInterface rowMeta0 = new RowMeta();
    rowMeta0.addValueMeta(meta0);
    Object[] objects0 = { object0 };
    RowMetaInterface rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(meta2);
    Object[] objects1 = { object1 };
    when(stepPartitioningMeta.getPartition(rowMeta0, objects0)).thenReturn(0);
    when(stepPartitioningMeta.getPartition(rowMeta1, objects1)).thenReturn(1);
    BlockingRowSet[] rowSet = { new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2) };
    List<RowSet> outputRowSets = new ArrayList<RowSet>();
    outputRowSets.addAll(Arrays.asList(rowSet));
    BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    baseStep.setStopped(false);
    baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_SPECIAL);
    baseStep.setOutputRowSets(outputRowSets);
    baseStep.putRow(rowMeta0, objects0);
    baseStep.putRow(rowMeta1, objects1);
    assertEquals(object0, baseStep.getOutputRowSets().get(0).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(1).getRow()[0]);
    assertEquals(object0, baseStep.getOutputRowSets().get(2).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(3).getRow()[0]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) BasePartitioner(org.pentaho.di.trans.BasePartitioner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NonAccessibleFileObject(org.pentaho.di.core.fileinput.NonAccessibleFileObject) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 75 with RowSet

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

the class RegexEvalUnitTest method testOutputIsMuchBiggerThanInputDoesntThrowArrayIndexOutOfBounds.

@Test
public void testOutputIsMuchBiggerThanInputDoesntThrowArrayIndexOutOfBounds() throws KettleException {
    RegexEval regexEval = new RegexEval(stepMockHelper.stepMeta, stepMockHelper.stepDataInterface, 0, stepMockHelper.transMeta, stepMockHelper.trans);
    when(stepMockHelper.processRowsStepMetaInterface.isAllowCaptureGroupsFlagSet()).thenReturn(true);
    String[] outFields = new String[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k" };
    when(stepMockHelper.processRowsStepMetaInterface.getFieldName()).thenReturn(outFields);
    when(stepMockHelper.processRowsStepMetaInterface.getMatcher()).thenReturn("\\.+");
    stepMockHelper.processRowsStepDataInterface.pattern = Pattern.compile("(a)(b)(c)(d)(e)(f)(g)(h)(i)(j)(k)");
    Object[] inputRow = new Object[] {};
    RowSet inputRowSet = stepMockHelper.getMockInputRowSet(inputRow);
    RowMetaInterface mockInputRowMeta = mock(RowMetaInterface.class);
    RowMetaInterface mockOutputRoMeta = mock(RowMetaInterface.class);
    when(mockOutputRoMeta.size()).thenReturn(outFields.length);
    when(mockInputRowMeta.size()).thenReturn(0);
    when(inputRowSet.getRowMeta()).thenReturn(mockInputRowMeta);
    when(mockInputRowMeta.clone()).thenReturn(mockOutputRoMeta);
    when(mockInputRowMeta.isNull(any(Object[].class), anyInt())).thenReturn(true);
    regexEval.addRowSetToInputRowSets(inputRowSet);
    regexEval.init(stepMockHelper.initStepMetaInterface, stepMockHelper.initStepDataInterface);
    regexEval.processRow(stepMockHelper.processRowsStepMetaInterface, stepMockHelper.processRowsStepDataInterface);
}
Also used : RowSet(org.pentaho.di.core.RowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) 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