Search in sources :

Example 11 with BlockedException

use of org.teiid.common.buffer.BlockedException in project teiid by teiid.

the class QueryProcessor method nextBatchDirect.

private TupleBatch nextBatchDirect() throws BlockedException, TeiidProcessingException, TeiidComponentException {
    boolean done = false;
    TupleBatch result = null;
    try {
        init();
        long currentTime = System.currentTimeMillis();
        Assertion.assertTrue(!processorClosed);
        while (currentTime < context.getTimeSliceEnd() || context.isNonBlocking()) {
            if (requestCanceled) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, this.context.getRequestId()));
            }
            if (currentTime > context.getTimeoutEnd()) {
                throw new TeiidProcessingException(QueryPlugin.Event.TEIID30161, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30161));
            }
            result = processPlan.nextBatch();
            if (continuous) {
                result.setRowOffset(rowOffset);
                if (result.getTerminationFlag()) {
                    result.setTermination(TupleBatch.ITERATION_TERMINATED);
                    List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]);
                    result.getTuples().add(terminationTuple);
                    this.context.getTupleSourceCache().close();
                    this.processPlan.close();
                    this.processPlan.reset();
                    this.context.incrementReuseCount();
                    this.open = false;
                }
                rowOffset = result.getEndRow() + 1;
            }
            if (result.getTermination() != TupleBatch.NOT_TERMINATED) {
                if (result.getTerminationFlag()) {
                    done = true;
                }
                break;
            }
            if (result.getRowCount() > 0) {
                break;
            }
        }
    } catch (BlockedException e) {
        throw e;
    } catch (TeiidException e) {
        closeProcessing();
        if (e instanceof TeiidProcessingException) {
            throw (TeiidProcessingException) e;
        }
        if (e instanceof TeiidComponentException) {
            throw (TeiidComponentException) e;
        }
        throw new TeiidComponentException(QueryPlugin.Event.TEIID30162, e);
    }
    if (done) {
        closeProcessing();
    }
    if (result == null) {
        RequestWorkItem workItem = this.getContext().getWorkItem();
        if (workItem != null) {
            // if we have a workitem (non-test scenario) then before
            // throwing exprired time slice we need to indicate there's more work
            workItem.moreWork();
        }
        throw EXPIRED_TIME_SLICE;
    }
    return result;
}
Also used : RequestWorkItem(org.teiid.dqp.internal.process.RequestWorkItem) TeiidComponentException(org.teiid.core.TeiidComponentException) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TeiidException(org.teiid.core.TeiidException)

Example 12 with BlockedException

use of org.teiid.common.buffer.BlockedException in project teiid by teiid.

the class TestAsyncTupleSource method testTupleSource.

@Test
public void testTupleSource() throws TeiidComponentException, TeiidProcessingException {
    AsyncTupleSource ats = new AsyncTupleSource(new Callable<TupleSource>() {

        @Override
        public TupleSource call() throws Exception {
            return new CollectionTupleSource(Arrays.asList(Arrays.asList(1), Arrays.asList(2)).iterator());
        }
    }, new CommandContext());
    for (int i = 0; i < 20; i++) {
        try {
            assertEquals(Arrays.asList(1), ats.nextTuple());
            break;
        } catch (BlockedException e) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e1) {
            }
        }
    }
    assertEquals(Arrays.asList(2), ats.nextTuple());
    assertNull(ats.nextTuple());
}
Also used : CommandContext(org.teiid.query.util.CommandContext) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) BlockedException(org.teiid.common.buffer.BlockedException) BlockedException(org.teiid.common.buffer.BlockedException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) Test(org.junit.Test)

Example 13 with BlockedException

use of org.teiid.common.buffer.BlockedException in project teiid by teiid.

the class TestProcessor method doProcess.

public static long doProcess(ProcessorPlan plan, ProcessorDataManager dataManager, List[] expectedResults, CommandContext context) throws Exception {
    BufferManager bufferMgr = context.getBufferManager();
    if (bufferMgr == null) {
        BufferManagerImpl bm = BufferManagerFactory.createBufferManager();
        bm.setProcessorBatchSize(context.getProcessorBatchSize());
        context.setBufferManager(bm);
        bufferMgr = bm;
    }
    context.getNextRand(0);
    if (context.getTempTableStore() == null) {
        context.setTempTableStore(new TempTableStore(context.getConnectionId(), TransactionMode.ISOLATE_WRITES));
    }
    if (context.getGlobalTableStore() == null) {
        GlobalTableStoreImpl gts = new GlobalTableStoreImpl(bufferMgr, null, context.getMetadata());
        context.setGlobalTableStore(gts);
    }
    if (!(dataManager instanceof TempTableDataManager)) {
        SessionAwareCache<CachedResults> cache = new SessionAwareCache<CachedResults>("resultset", DefaultCacheFactory.INSTANCE, SessionAwareCache.Type.RESULTSET, 0);
        cache.setTupleBufferCache(bufferMgr);
        dataManager = new TempTableDataManager(dataManager, bufferMgr, cache);
    }
    if (context.getQueryProcessorFactory() == null) {
        context.setQueryProcessorFactory(new QueryProcessorFactoryImpl(bufferMgr, dataManager, new DefaultCapabilitiesFinder(), null, context.getMetadata()));
    }
    TupleBuffer id = null;
    long rowCount = 0;
    try {
        QueryProcessor processor = new QueryProcessor(plan, context, bufferMgr, dataManager);
        // processor.setNonBlocking(true);
        BatchCollector collector = processor.createBatchCollector();
        for (int i = 0; i < 100; i++) {
            try {
                id = collector.collectTuples();
                break;
            } catch (BlockedException e) {
            }
        }
        if (id == null) {
            fail("did not complete processing");
        }
        rowCount = id.getRowCount();
        if (DEBUG) {
            // $NON-NLS-1$
            System.out.println("\nResults:\n" + id.getSchema());
            TupleSource ts2 = id.createIndexedTupleSource();
            for (int j = 0; j < rowCount; j++) {
                // $NON-NLS-1$ //$NON-NLS-2$
                System.out.println("" + j + ": " + ts2.nextTuple());
            }
        }
        if (expectedResults != null) {
            examineResults(expectedResults, bufferMgr, id);
        }
    } finally {
        if (id != null) {
            id.remove();
        }
    }
    return rowCount;
}
Also used : TempTableStore(org.teiid.query.tempdata.TempTableStore) BufferManagerImpl(org.teiid.common.buffer.impl.BufferManagerImpl) SessionAwareCache(org.teiid.dqp.internal.process.SessionAwareCache) TempTableDataManager(org.teiid.query.tempdata.TempTableDataManager) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BufferManager(org.teiid.common.buffer.BufferManager) DefaultCapabilitiesFinder(org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder) BlockedException(org.teiid.common.buffer.BlockedException) CachedResults(org.teiid.dqp.internal.process.CachedResults) TupleSource(org.teiid.common.buffer.TupleSource) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) QueryProcessorFactoryImpl(org.teiid.dqp.internal.process.QueryProcessorFactoryImpl)

Example 14 with BlockedException

use of org.teiid.common.buffer.BlockedException in project teiid by teiid.

the class TestBatchedUpdateNode method helpTestNextBatch.

private FakePDM helpTestNextBatch(String[] commands, int[] expectedResults) throws Exception {
    int numExecutedCommands = 0;
    for (int i = 0; i < expectedResults.length; i++) {
        numExecutedCommands += expectedResults[i];
    }
    FakePDM fakePDM = new FakePDM(numExecutedCommands);
    BatchedUpdateNode node = helpOpen(commands, fakePDM);
    TupleBatch batch = null;
    try {
        batch = node.nextBatch();
    } catch (BlockedException e) {
        batch = node.nextBatch();
    }
    assertNotNull(batch);
    assertTrue(batch.getTerminationFlag());
    assertEquals(expectedResults.length, batch.getRowCount());
    for (int i = 0; i < expectedResults.length; i++) {
        List tuple = batch.getTuple(i + 1);
        assertNotNull(tuple);
        Object result = tuple.get(0);
        assertNotNull(result);
        assertEquals(new Integer(expectedResults[i]), result);
    }
    return fakePDM;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 15 with BlockedException

use of org.teiid.common.buffer.BlockedException in project teiid by teiid.

the class TestJoinNode method process.

private void process(List[] expectedResults) throws TeiidComponentException, TeiidProcessingException {
    join.open();
    int currentRow = 1;
    while (true) {
        try {
            TupleBatch batch = join.nextBatch();
            for (; currentRow <= batch.getEndRow(); currentRow++) {
                List tuple = batch.getTuple(currentRow);
                // $NON-NLS-1$
                assertEquals("Rows don't match at " + currentRow, expectedResults[currentRow - 1], tuple);
            }
            if (batch.getTerminationFlag()) {
                break;
            }
        } catch (BlockedException e) {
        // ignore and retry
        }
    }
    assertEquals(expectedResults.length, currentRow - 1);
    join.close();
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) BlockedException(org.teiid.common.buffer.BlockedException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Aggregations

BlockedException (org.teiid.common.buffer.BlockedException)45 TupleBatch (org.teiid.common.buffer.TupleBatch)16 ArrayList (java.util.ArrayList)15 List (java.util.List)15 TeiidProcessingException (org.teiid.core.TeiidProcessingException)15 TeiidComponentException (org.teiid.core.TeiidComponentException)13 TupleBuffer (org.teiid.common.buffer.TupleBuffer)10 CommandContext (org.teiid.query.util.CommandContext)10 TupleSource (org.teiid.common.buffer.TupleSource)8 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)8 Test (org.junit.Test)6 BufferManager (org.teiid.common.buffer.BufferManager)6 ExpressionEvaluationException (org.teiid.api.exception.query.ExpressionEvaluationException)5 FunctionExecutionException (org.teiid.api.exception.query.FunctionExecutionException)5 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)5 Command (org.teiid.query.sql.lang.Command)5 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)4 SQLException (java.sql.SQLException)3 QueryProcessingException (org.teiid.api.exception.query.QueryProcessingException)3