Search in sources :

Example 6 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class DataTierTupleSource method asynchGet.

private AtomicResultsMessage asynchGet() throws BlockedException, TeiidProcessingException, TeiidComponentException, TranslatorException {
    if (futureResult == null) {
        addWork();
    }
    if (!futureResult.isDone()) {
        // $NON-NLS-1$
        throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking on source query", aqr.getAtomicRequestID());
    }
    FutureWork<AtomicResultsMessage> currentResults = futureResult;
    futureResult = null;
    AtomicResultsMessage results = null;
    try {
        results = currentResults.get();
        if (results.getFinalRow() < 0) {
            addWork();
        }
    } catch (CancellationException e) {
        throw new TeiidProcessingException(e);
    } catch (InterruptedException e) {
        throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30503, e);
    } catch (ExecutionException e) {
        if (e.getCause() instanceof TeiidProcessingException) {
            throw (TeiidProcessingException) e.getCause();
        }
        if (e.getCause() instanceof TeiidComponentException) {
            throw (TeiidComponentException) e.getCause();
        }
        if (e.getCause() instanceof TranslatorException) {
            throw (TranslatorException) e.getCause();
        }
        if (e.getCause() instanceof RuntimeException) {
            throw (RuntimeException) e.getCause();
        }
        // shouldn't happen
        throw new RuntimeException(e);
    }
    return results;
}
Also used : TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) CancellationException(java.util.concurrent.CancellationException) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TeiidComponentException(org.teiid.core.TeiidComponentException) TranslatorException(org.teiid.translator.TranslatorException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 7 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class DataTierTupleSource method nextTuple.

public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException {
    if (waitUntil > 0 && waitUntil > System.currentTimeMillis()) {
        if (!this.cwi.isDataAvailable()) {
            // $NON-NLS-1$
            throw BlockedException.block(aqr.getAtomicRequestID(), "Blocking until", waitUntil);
        }
        this.waitUntil = 0;
    }
    while (true) {
        if (arm == null) {
            if (isDone()) {
                // TODO: could throw an illegal state exception
                return null;
            }
            boolean partial = false;
            AtomicResultsMessage results = null;
            boolean noResults = false;
            try {
                if (futureResult != null || !aqr.isSerial()) {
                    results = asynchGet();
                } else {
                    results = getResults();
                }
                // check for update events
                if (index == 0 && this.dtm.detectChangeEvents()) {
                    Command command = aqr.getCommand();
                    int commandIndex = 0;
                    if (RelationalNodeUtil.isUpdate(command)) {
                        long ts = System.currentTimeMillis();
                        checkForUpdates(results, command, dtm.getEventDistributor(), commandIndex, ts);
                    } else if (command instanceof BatchedUpdateCommand) {
                        long ts = System.currentTimeMillis();
                        BatchedUpdateCommand bac = (BatchedUpdateCommand) command;
                        for (Command uc : bac.getUpdateCommands()) {
                            checkForUpdates(results, uc, dtm.getEventDistributor(), commandIndex++, ts);
                        }
                    }
                }
            } catch (TranslatorException e) {
                errored = true;
                results = exceptionOccurred(e);
                partial = true;
            } catch (BlockedException e) {
                noResults = true;
                throw e;
            } catch (DataNotAvailableException e) {
                noResults = true;
                handleDataNotAvailable(e);
                continue;
            } finally {
                if (!noResults && results == null) {
                    errored = true;
                }
            }
            receiveResults(results, partial);
        }
        if (index < arm.getResults().length) {
            if (limit-- == 0) {
                this.done = true;
                arm = null;
                return null;
            }
            return this.arm.getResults()[index++];
        }
        arm = null;
        if (isDone()) {
            return null;
        }
    }
}
Also used : Command(org.teiid.query.sql.lang.Command) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) BatchedUpdateCommand(org.teiid.query.sql.lang.BatchedUpdateCommand) BlockedException(org.teiid.common.buffer.BlockedException)

Example 8 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class DataTierTupleSource method getResults.

AtomicResultsMessage getResults() throws BlockedException, TeiidComponentException, TranslatorException {
    AtomicResultsMessage results = null;
    if (cancelAsynch) {
        return null;
    }
    running = true;
    try {
        if (!executed) {
            cwi.execute();
            executed = true;
        }
        results = cwi.more();
    } finally {
        running = false;
    }
    return results;
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage)

Example 9 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class DataTierTupleSource method exceptionOccurred.

AtomicResultsMessage exceptionOccurred(TranslatorException exception) throws TeiidComponentException, TeiidProcessingException {
    if (workItem.requestMsg.supportsPartialResults()) {
        AtomicResultsMessage emptyResults = new AtomicResultsMessage(new List[0]);
        emptyResults.setWarnings(Arrays.asList((Exception) exception));
        emptyResults.setFinalRow(this.rowsProcessed);
        return emptyResults;
    }
    fullyCloseSource();
    if (exception.getCause() instanceof TeiidComponentException) {
        throw (TeiidComponentException) exception.getCause();
    }
    if (exception.getCause() instanceof TeiidProcessingException) {
        throw (TeiidProcessingException) exception.getCause();
    }
    // $NON-NLS-1$
    throw new TeiidProcessingException(QueryPlugin.Event.TEIID30504, exception, this.getConnectorName() + ": " + exception.getMessage());
}
Also used : AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) TranslatorException(org.teiid.translator.TranslatorException) DataNotAvailableException(org.teiid.translator.DataNotAvailableException) CancellationException(java.util.concurrent.CancellationException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) BlockedException(org.teiid.common.buffer.BlockedException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 10 with AtomicResultsMessage

use of org.teiid.dqp.message.AtomicResultsMessage in project teiid by teiid.

the class ConnectorWorkItem method handleBatch.

protected AtomicResultsMessage handleBatch() throws TranslatorException {
    Assertion.assertTrue(!this.lastBatch);
    // $NON-NLS-1$
    LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.id, "Getting results from connector" });
    int batchSize = 0;
    List<List<?>> rows = new ResizingArrayList<List<?>>(batchSize / 4);
    try {
        while (batchSize < this.requestMsg.getFetchSize()) {
            List<?> row = this.execution.next();
            if (row == null) {
                this.lastBatch = true;
                break;
            }
            if (row.size() != this.expectedColumns) {
                // $NON-NLS-1$ //$NON-NLS-2$
                throw new AssertionError("Inproper results returned.  Expected " + this.expectedColumns + " columns, but was " + row.size());
            }
            try {
                try {
                    if (unmodifiableList) {
                        row = new ArrayList<Object>(row);
                    }
                    row = correctTypes(row);
                } catch (UnsupportedOperationException | ArrayStoreException e) {
                    // the translator should be modifiable, but we should be lax
                    if (unmodifiableList) {
                        throw e;
                    }
                    unmodifiableList = true;
                    row = new ArrayList<Object>(row);
                    row = correctTypes(row);
                }
            } catch (TeiidException e) {
                conversionError = e;
                break;
            }
            if (this.procedureBatchHandler != null) {
                row = this.procedureBatchHandler.padRow(row);
            }
            this.rowCount += 1;
            batchSize++;
            rows.add(row);
            // Check for max result rows exceeded
            if (this.requestMsg.getMaxResultRows() > -1 && this.rowCount >= this.requestMsg.getMaxResultRows()) {
                if (this.rowCount == this.requestMsg.getMaxResultRows() && !this.requestMsg.isExceptionOnMaxRows()) {
                    // $NON-NLS-1$
                    LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.id, "Exceeded max, returning", this.requestMsg.getMaxResultRows() });
                    this.lastBatch = true;
                    break;
                } else if (this.rowCount > this.requestMsg.getMaxResultRows() && this.requestMsg.isExceptionOnMaxRows()) {
                    // $NON-NLS-1$
                    String msg = QueryPlugin.Util.getString("ConnectorWorker.MaxResultRowsExceed", this.requestMsg.getMaxResultRows());
                    throw new TranslatorException(QueryPlugin.Event.TEIID30478, msg);
                }
            }
        }
    } catch (DataNotAvailableException e) {
        if (rows.size() == 0) {
            throw e;
        }
        if (e.getWaitUntil() != null) {
            // we have an await until that we need to enforce
            this.dnae = e;
        }
    // else we can just ignore the delay
    }
    if (lastBatch) {
        if (this.procedureBatchHandler != null) {
            List<?> row = this.procedureBatchHandler.getParameterRow();
            if (row != null) {
                try {
                    row = correctTypes(row);
                    rows.add(row);
                    this.rowCount += 1;
                } catch (TeiidException e) {
                    lastBatch = false;
                    conversionError = e;
                }
            }
        }
        // $NON-NLS-1$\
        LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.id, "Obtained last batch, total row count:", rowCount });
    } else {
        // $NON-NLS-1$
        LogManager.logDetail(LogConstants.CTX_CONNECTOR, new Object[] { this.id, "Obtained results from connector, current row count:", rowCount });
    }
    int currentRowCount = rows.size();
    if (!lastBatch && currentRowCount == 0) {
        // Defect 13366 - Should send all batches, even if they're zero size.
        // Log warning if received a zero-size non-last batch from the connector.
        LogManager.logWarning(LogConstants.CTX_CONNECTOR, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30004, requestMsg.getConnectorName()));
    }
    AtomicResultsMessage response = createResultsMessage(rows.toArray(new List[currentRowCount]));
    // if we need to keep the execution alive, then we can not support implicit close.
    response.setSupportsImplicitClose(!this.securityContext.keepExecutionAlive() && !explicitClose);
    response.setWarnings(this.securityContext.getWarnings());
    if (this.securityContext.getCacheDirective() != null) {
        response.setScope(this.securityContext.getCacheDirective().getScope());
    }
    if (this.securityContext.getScope() != null && (response.getScope() == null || response.getScope().compareTo(this.securityContext.getScope()) > 0)) {
        response.setScope(this.securityContext.getScope());
    }
    if (lastBatch) {
        response.setFinalRow(rowCount);
    }
    return response;
}
Also used : ArrayList(java.util.ArrayList) ResizingArrayList(org.teiid.client.ResizingArrayList) SourceHint(org.teiid.query.sql.lang.SourceHint) SpecificHint(org.teiid.query.sql.lang.SourceHint.SpecificHint) TeiidException(org.teiid.core.TeiidException) List(java.util.List) ArrayList(java.util.ArrayList) ResizingArrayList(org.teiid.client.ResizingArrayList) AtomicResultsMessage(org.teiid.dqp.message.AtomicResultsMessage) ResizingArrayList(org.teiid.client.ResizingArrayList)

Aggregations

AtomicResultsMessage (org.teiid.dqp.message.AtomicResultsMessage)13 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 TranslatorException (org.teiid.translator.TranslatorException)5 BufferManager (org.teiid.common.buffer.BufferManager)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 AtomicRequestMessage (org.teiid.dqp.message.AtomicRequestMessage)3 QueryExpression (org.teiid.language.QueryExpression)3 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)3 DataNotAvailableException (org.teiid.translator.DataNotAvailableException)3 ExecutionContext (org.teiid.translator.ExecutionContext)3 ExecutionFactory (org.teiid.translator.ExecutionFactory)3 ResultSetExecution (org.teiid.translator.ResultSetExecution)3 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TeiidProcessingException (org.teiid.core.TeiidProcessingException)2 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1