Search in sources :

Example 26 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class RelationalNode method getBuffer.

/**
 * return the final tuple buffer or null if not available
 * @return
 * @throws TeiidProcessingException
 * @throws TeiidComponentException
 * @throws BlockedException
 */
public final TupleBuffer getBuffer(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException {
    CommandContext context = this.getContext();
    if (context != null && context.isCancelled()) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
    }
    boolean recordStats = context != null && context.getCollectNodeStatistics() && !isLastBatch();
    try {
        // start timer for this batch
        if (recordStats) {
            this.getProcessingState().nodeStatistics.startBatchTimer();
        }
        TupleBuffer buffer = getBufferDirect(maxRows);
        terminateBatches();
        if (recordStats) {
            // stop timer for this batch (normal)
            this.getProcessingState().nodeStatistics.stopBatchTimer();
            this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(buffer.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
            this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
            if (LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_DQP, MessageLevel.TRACE) && !buffer.isForwardOnly()) {
                for (long i = 1; i <= buffer.getRowCount(); i += buffer.getBatchSize()) {
                    TupleBatch tb = buffer.getBatch(i);
                    recordBatch(tb);
                }
            }
            recordStats = false;
        }
        return buffer;
    } catch (BlockedException e) {
        if (recordStats) {
            // stop timer for this batch (BlockedException)
            this.getProcessingState().nodeStatistics.stopBatchTimer();
            this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
            recordStats = false;
        }
        throw e;
    } finally {
        if (recordStats) {
            this.getProcessingState().nodeStatistics.stopBatchTimer();
        }
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) TupleBuffer(org.teiid.common.buffer.TupleBuffer) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 27 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class RelationalNode method nextBatch.

/**
 * Wrapper for nextBatchDirect that does performance timing - callers
 * should always call this rather than nextBatchDirect().
 * @return
 * @throws BlockedException
 * @throws TeiidComponentException
 * @since 4.2
 */
public final TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
    CommandContext context = this.getContext();
    if (context != null && context.isCancelled()) {
        throw new TeiidProcessingException(QueryPlugin.Event.TEIID30160, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30160, getContext().getRequestId()));
    }
    boolean recordStats = context != null && context.getCollectNodeStatistics();
    try {
        while (true) {
            // start timer for this batch
            if (recordStats) {
                this.getProcessingState().nodeStatistics.startBatchTimer();
            }
            TupleBatch batch = nextBatchDirect();
            if (recordStats) {
                // stop timer for this batch (normal)
                this.getProcessingState().nodeStatistics.stopBatchTimer();
                this.getProcessingState().nodeStatistics.collectCumulativeNodeStats((long) batch.getRowCount(), RelationalNodeStatistics.BATCHCOMPLETE_STOP);
                if (batch.getTerminationFlag()) {
                    this.getProcessingState().nodeStatistics.collectNodeStats(this.getChildren());
                // this.nodeStatistics.dumpProperties(this.getClassName());
                }
                this.recordBatch(batch);
                recordStats = false;
            }
            // this processing style however against the spirit of batch processing (but was already utilized by Sort and Grouping nodes)
            if (batch.getRowCount() != 0 || batch.getTerminationFlag()) {
                if (batch.getTerminationFlag()) {
                    close();
                }
                return batch;
            }
        }
    } catch (BlockedException e) {
        if (recordStats) {
            // stop timer for this batch (BlockedException)
            this.getProcessingState().nodeStatistics.stopBatchTimer();
            this.getProcessingState().nodeStatistics.collectCumulativeNodeStats(null, RelationalNodeStatistics.BLOCKEDEXCEPTION_STOP);
            recordStats = false;
        }
        throw e;
    } finally {
        if (recordStats) {
            this.getProcessingState().nodeStatistics.stopBatchTimer();
        }
    }
}
Also used : CommandContext(org.teiid.query.util.CommandContext) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TupleBatch(org.teiid.common.buffer.TupleBatch)

Example 28 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException 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 29 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException 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 30 with TeiidProcessingException

use of org.teiid.core.TeiidProcessingException in project teiid by teiid.

the class TestSocketRemoting method testMethodInvocation.

@Test
public void testMethodInvocation() throws Exception {
    ClientServiceRegistryImpl csr = new ClientServiceRegistryImpl() {

        @Override
        public ClassLoader getCallerClassloader() {
            return getClass().getClassLoader();
        }
    };
    csr.registerClientService(ILogon.class, new ILogon() {

        public ResultsFuture<?> logoff() throws InvalidSessionException {
            ResultsFuture<?> result = new ResultsFuture<Void>();
            // $NON-NLS-1$
            result.getResultsReceiver().exceptionOccurred(new TeiidComponentException("some exception"));
            return result;
        }

        public LogonResult logon(Properties connectionProperties) throws LogonException, TeiidComponentException {
            return new LogonResult();
        }

        // tests asynch where we don't care about the result
        public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
            return null;
        }

        @Override
        public ResultsFuture<?> ping(Collection<String> sessions) throws TeiidComponentException, CommunicationException {
            return null;
        }

        @Override
        public void assertIdentity(SessionToken sessionId) throws InvalidSessionException, TeiidComponentException {
        }

        @Override
        public LogonResult neogitiateGssLogin(Properties connectionProperties, byte[] serviceToken, boolean createSession) throws LogonException {
            return null;
        }
    }, // $NON-NLS-1$
    "foo");
    // $NON-NLS-1$
    csr.registerClientService(FakeService.class, new FakeServiceImpl(), "foo");
    final FakeClientServerInstance serverInstance = new FakeClientServerInstance(csr);
    SocketServerConnection connection = createFakeConnection(serverInstance);
    ILogon logon = connection.getService(ILogon.class);
    Future<?> result = logon.ping();
    assertNull(result.get(0, TimeUnit.MILLISECONDS));
    result = logon.logoff();
    try {
        result.get(0, TimeUnit.MICROSECONDS);
        // $NON-NLS-1$
        fail("exception expected");
    } catch (ExecutionException e) {
        assertTrue(e.getCause() instanceof TeiidComponentException);
    }
    FakeService service = connection.getService(FakeService.class);
    Future<Integer> asynchInteger = service.asynchResult();
    assertEquals(new Integer(5), asynchInteger.get(0, TimeUnit.MILLISECONDS));
    try {
        service.exceptionMethod();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (TeiidProcessingException e) {
    }
    DQP dqp = connection.getService(DQP.class);
    try {
        ResultsFuture<?> future = dqp.begin();
        future.get();
        // $NON-NLS-1$
        fail("exception expected");
    } catch (Exception e) {
        // $NON-NLS-1$
        assertTrue(e.getMessage().indexOf("Component not found:") != -1);
    }
}
Also used : LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) TeiidProcessingException(org.teiid.core.TeiidProcessingException) LogonException(org.teiid.client.security.LogonException) ExecutionException(java.util.concurrent.ExecutionException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQP(org.teiid.client.DQP) CommunicationException(org.teiid.net.CommunicationException) SessionToken(org.teiid.client.security.SessionToken) ILogon(org.teiid.client.security.ILogon) InvalidSessionException(org.teiid.client.security.InvalidSessionException) TeiidComponentException(org.teiid.core.TeiidComponentException) LogonException(org.teiid.client.security.LogonException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) CommunicationException(org.teiid.net.CommunicationException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ExecutionException(java.util.concurrent.ExecutionException) ConnectionException(org.teiid.net.ConnectionException) ResultsFuture(org.teiid.client.util.ResultsFuture) TeiidComponentException(org.teiid.core.TeiidComponentException) SocketServerConnection(org.teiid.net.socket.SocketServerConnection) Test(org.junit.Test)

Aggregations

TeiidProcessingException (org.teiid.core.TeiidProcessingException)92 TeiidComponentException (org.teiid.core.TeiidComponentException)30 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)17 SQLException (java.sql.SQLException)16 BlockedException (org.teiid.common.buffer.BlockedException)16 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)14 LanguageObject (org.teiid.query.sql.LanguageObject)13 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)13 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)12 List (java.util.List)11 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)10 QueryPlannerException (org.teiid.api.exception.query.QueryPlannerException)9 TupleSource (org.teiid.common.buffer.TupleSource)9 TupleBatch (org.teiid.common.buffer.TupleBatch)8 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)6