Search in sources :

Example 1 with RowMetaAndData

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

the class DefaultCache method storeRowInCache.

@Override
public void storeRowInCache(DatabaseLookupMeta meta, RowMetaInterface lookupMeta, Object[] lookupRow, Object[] add) {
    RowMetaAndData rowMetaAndData = new RowMetaAndData(lookupMeta, lookupRow);
    // DEinspanjer 2009-02-01 XXX: I want to write a test case to prove this point before checking in.
    // /* Don't insert a row with a duplicate key into the cache. It doesn't seem
    // * to serve a useful purpose and can potentially cause the step to return
    // * different values over the life of the transformation (if the source DB rows change)
    // * Additionally, if using the load all data feature, re-inserting would reverse the order
    // * specified in the step.
    // */
    // if (!data.look.containsKey(rowMetaAndData)) {
    // data.look.put(rowMetaAndData, new TimedRow(add));
    // }
    map.put(rowMetaAndData, new TimedRow(add));
    // method would throw out entries if the previous cache size wasn't big enough.
    if (!meta.isLoadingAllDataInCache() && meta.getCacheSize() > 0 && map.size() > meta.getCacheSize()) {
        List<RowMetaAndData> keys = new ArrayList<RowMetaAndData>(map.keySet());
        List<Date> samples = new ArrayList<Date>();
        int incr = keys.size() / 10;
        if (incr == 0) {
            incr = 1;
        }
        for (int k = 0; k < keys.size(); k += incr) {
            RowMetaAndData key = keys.get(k);
            TimedRow timedRow = map.get(key);
            samples.add(timedRow.getLogDate());
        }
        Collections.sort(samples);
        if (samples.size() > 1) {
            Date smallest = samples.get(1);
            // Everything below the smallest date goes away...
            for (RowMetaAndData key : keys) {
                TimedRow timedRow = map.get(key);
                if (timedRow.getLogDate().compareTo(smallest) < 0) {
                    map.remove(key);
                }
            }
        }
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ArrayList(java.util.ArrayList) TimedRow(org.pentaho.di.core.TimedRow) Date(java.util.Date)

Example 2 with RowMetaAndData

use of org.pentaho.di.core.RowMetaAndData in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceTest method testReplayFullCache.

@Test
public void testReplayFullCache() throws Exception {
    DataServiceExecutor executor = dataServiceExecutor(BASE_QUERY);
    CachedService cachedService = CachedService.complete(testData);
    RowProducer rowProducer = genTrans.addRowProducer(INJECTOR_STEP, 0);
    // Activate cachedServiceLoader
    Executor mockExecutor = mock(Executor.class);
    final CachedServiceLoader cachedServiceLoader = new CachedServiceLoader(cachedService, mockExecutor);
    ListenableFuture<Integer> replay = cachedServiceLoader.replay(executor);
    ArgumentCaptor<Runnable> replayRunnable = ArgumentCaptor.forClass(Runnable.class);
    verify(mockExecutor).execute(replayRunnable.capture());
    stepMetaDataCombi.step = inputStep;
    stepMetaDataCombi.meta = inputStepMetaInterface;
    stepMetaDataCombi.data = inputStepDataInterface;
    List<StepMetaDataCombi> stepMetaDataCombis = new ArrayList<>();
    stepMetaDataCombis.add(stepMetaDataCombi);
    when(serviceTrans.getSteps()).thenReturn(stepMetaDataCombis);
    // Simulate executing data service
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.READY);
    executor.executeListeners(DataServiceExecutor.ExecutionPoint.START);
    // Verify that serviceTrans never started, genTrans is accepting rows
    verify(serviceTrans).stopAll();
    verify(inputStep).setOutputDone();
    verify(inputStep).dispose(inputStepMetaInterface, inputStepDataInterface);
    verify(inputStep).markStop();
    verify(serviceTrans, never()).startThreads();
    verify(genTrans).startThreads();
    when(rowProducer.putRowWait(any(RowMetaInterface.class), any(Object[].class), anyInt(), any(TimeUnit.class))).then(new Answer<Boolean>() {

        int calls = 0;

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            // Simulate full row set on tenth call
            return ++calls != 10;
        }
    });
    when(genTrans.isRunning()).thenReturn(true);
    // Run cache loader (would be asynchronous)
    replayRunnable.getValue().run();
    assertThat(replay.get(1, TimeUnit.SECONDS), equalTo(testData.size()));
    InOrder rowsProduced = inOrder(rowProducer);
    for (int i = 0; i < testData.size(); i++) {
        RowMetaAndData metaAndData = testData.get(i);
        // Tenth row was called twice, since row set was full
        Object[] data = metaAndData.getData();
        rowsProduced.verify(rowProducer, times(i == 9 ? 2 : 1)).putRowWait(eq(metaAndData.getRowMeta()), and(eq(data), AdditionalMatchers.not(same(data))), anyInt(), any(TimeUnit.class));
    }
    rowsProduced.verify(rowProducer).finished();
    rowsProduced.verifyNoMoreInteractions();
}
Also used : RowProducer(org.pentaho.di.trans.RowProducer) InOrder(org.mockito.InOrder) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) ArrayList(java.util.ArrayList) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) DataServiceExecutor(org.pentaho.di.trans.dataservice.DataServiceExecutor) Executor(java.util.concurrent.Executor) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) InvocationOnMock(org.mockito.invocation.InvocationOnMock) StepMetaDataCombi(org.pentaho.di.trans.step.StepMetaDataCombi) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.Test)

Example 3 with RowMetaAndData

use of org.pentaho.di.core.RowMetaAndData in project pdi-dataservice-server-plugin by pentaho.

the class CachedServiceTest method setUp.

@Before
public void setUp() throws Exception {
    rowMeta = new RowMeta();
    rowMeta.addValueMeta(new ValueMetaString("ID"));
    rowMeta.addValueMeta(new ValueMetaInteger("A"));
    rowMeta.addValueMeta(new ValueMetaInteger("B"));
    testData = Lists.newArrayListWithExpectedSize(100);
    for (long i = 0; i < 100; i++) {
        testData.add(new RowMetaAndData(rowMeta, String.valueOf(i), i % 13, i % 17));
    }
    when(serviceTrans.findRunThread(SERVICE_STEP)).thenReturn(serviceStep);
    when(serviceStep.getTrans()).thenReturn(serviceTrans);
    when(sqlTransGenerator.getInjectorStepName()).thenReturn(INJECTOR_STEP);
    transMeta = serviceTrans.getTransMeta();
    when(transMeta.getCacheVersion()).thenReturn(1);
    dataServiceMeta = new DataServiceMeta(transMeta);
    dataServiceMeta.setName(SERVICE_NAME);
    dataServiceMeta.setStepname(SERVICE_STEP);
    when(transMeta.getStepFields(SERVICE_STEP)).thenReturn(rowMeta);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) RowMeta(org.pentaho.di.core.row.RowMeta) DataServiceMeta(org.pentaho.di.trans.dataservice.DataServiceMeta) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger) Before(org.junit.Before)

Example 4 with RowMetaAndData

use of org.pentaho.di.core.RowMetaAndData in project pdi-dataservice-server-plugin by pentaho.

the class ServiceObserverTest method testRowIterator.

@Test
public void testRowIterator() throws Exception {
    CountDownLatch delayRowsLatch = new CountDownLatch(1);
    CountDownLatch firstRowLatch = new CountDownLatch(1);
    ServiceObserver serviceObserver = new ServiceObserver(executor) {

        @Override
        public void run() {
            rowMetaAndData.add(new RowMetaAndData());
            firstRowLatch.countDown();
            try {
                delayRowsLatch.await();
                rowMetaAndData.add(new RowMetaAndData());
                latch.countDown();
                rowMetaAndData.add(new RowMetaAndData());
                latch.countDown();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            isRunning = false;
        }
    };
    Executors.newSingleThreadExecutor().submit(serviceObserver);
    firstRowLatch.await();
    Iterator<RowMetaAndData> rows = serviceObserver.rows();
    assertTrue(rows.hasNext());
    rows.next();
    Executors.newSingleThreadScheduledExecutor().schedule(delayRowsLatch::countDown, 1100, TimeUnit.MILLISECONDS);
    assertTrue(rows.hasNext());
    rows.next();
    assertTrue(rows.hasNext());
    rows.next();
    assertFalse(rows.hasNext());
    delayRowsLatch.countDown();
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with RowMetaAndData

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

the class KettleDatabaseRepository method insertStepDatabase.

public synchronized void insertStepDatabase(ObjectId id_transformation, ObjectId id_step, ObjectId id_database) throws KettleException {
    // First check if the relationship is already there.
    // There is no need to store it twice!
    RowMetaAndData check = getStepDatabase(id_step);
    if (check.getInteger(0) == null) {
        RowMetaAndData table = new RowMetaAndData();
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_TRANSFORMATION), id_transformation);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_STEP), id_step);
        table.addValue(new ValueMetaInteger(KettleDatabaseRepository.FIELD_STEP_DATABASE_ID_DATABASE), id_database);
        connectionDelegate.insertTableRow(KettleDatabaseRepository.TABLE_R_STEP_DATABASE, table);
    }
}
Also used : RowMetaAndData(org.pentaho.di.core.RowMetaAndData) ValueMetaInteger(org.pentaho.di.core.row.value.ValueMetaInteger)

Aggregations

RowMetaAndData (org.pentaho.di.core.RowMetaAndData)588 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)231 ArrayList (java.util.ArrayList)182 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)155 Test (org.junit.Test)125 TransMeta (org.pentaho.di.trans.TransMeta)125 KettleException (org.pentaho.di.core.exception.KettleException)94 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)94 StepMeta (org.pentaho.di.trans.step.StepMeta)83 Trans (org.pentaho.di.trans.Trans)79 StepInterface (org.pentaho.di.trans.step.StepInterface)79 TransHopMeta (org.pentaho.di.trans.TransHopMeta)77 RowStepCollector (org.pentaho.di.trans.RowStepCollector)76 LongObjectId (org.pentaho.di.repository.LongObjectId)75 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)72 KettleValueException (org.pentaho.di.core.exception.KettleValueException)60 RowMeta (org.pentaho.di.core.row.RowMeta)59 RowProducer (org.pentaho.di.trans.RowProducer)57 DummyTransMeta (org.pentaho.di.trans.steps.dummytrans.DummyTransMeta)55 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)54