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;
}
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;
}
}
}
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;
}
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());
}
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;
}
Aggregations