use of org.teiid.common.buffer.TupleBatch 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();
}
}
}
use of org.teiid.common.buffer.TupleBatch 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();
}
}
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class RelationalNode method pullBatch.
protected TupleBatch pullBatch() {
TupleBatch batch = null;
if (this.getProcessingState().batchRows != null) {
batch = new TupleBatch(this.getProcessingState().beginBatch, this.getProcessingState().batchRows);
getProcessingState().beginBatch += this.getProcessingState().batchRows.size();
} else {
batch = new TupleBatch(this.getProcessingState().beginBatch, Collections.EMPTY_LIST);
}
batch.setTerminationFlag(this.getProcessingState().lastBatch);
// Reset batch state
this.getProcessingState().batchRows = null;
this.getProcessingState().lastBatch = false;
// Return batch
return batch;
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class ForEachRowPlan method nextBatch.
@Override
public TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (planContext != null) {
this.getContext().getTransactionServer().resume(planContext);
}
try {
while (true) {
if (currentTuple == null) {
if (nextTuple != null) {
currentTuple = nextTuple;
} else if (!nextNull) {
currentTuple = tupleSource.nextTuple();
}
if (currentTuple == null) {
if (this.planContext != null) {
TransactionService ts = this.getContext().getTransactionServer();
ts.commit(this.planContext);
this.planContext = null;
}
TupleBatch result = new TupleBatch(1, new List[] { Arrays.asList((int) Math.min(Integer.MAX_VALUE, updateCount)) });
result.setTerminationFlag(true);
return result;
}
}
if (first) {
TransactionContext tc = this.getContext().getTransactionContext();
if (this.planContext == null && tc != null && tc.getTransactionType() == Scope.NONE) {
Boolean txnRequired = rowProcedure.requiresTransaction(false);
boolean start = false;
if (txnRequired == null) {
nextTuple = tupleSource.nextTuple();
if (nextTuple != null) {
start = true;
} else {
nextNull = true;
}
} else if (Boolean.TRUE.equals(txnRequired)) {
start = true;
}
if (start) {
this.getContext().getTransactionServer().begin(tc);
this.planContext = tc;
}
}
first = false;
}
if (this.rowProcessor == null) {
rowProcedure.reset();
CommandContext context = getContext().clone();
this.rowProcessor = new QueryProcessor(rowProcedure, context, this.bufferMgr, this.dataMgr);
Evaluator eval = new Evaluator(lookupMap, dataMgr, context);
for (Map.Entry<ElementSymbol, Expression> entry : this.params.entrySet()) {
Integer index = this.lookupMap.get(entry.getValue());
if (index != null) {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), this.currentTuple.get(index));
} else {
rowProcedure.getCurrentVariableContext().setValue(entry.getKey(), eval.evaluate(entry.getValue(), this.currentTuple));
}
}
}
// save the variable context to get the key information
VariableContext vc = rowProcedure.getCurrentVariableContext();
// just getting the next batch is enough
this.rowProcessor.nextBatch();
if (insert) {
assignGeneratedKey(vc);
}
this.rowProcessor.closeProcessing();
this.rowProcessor = null;
this.currentTuple = null;
this.updateCount++;
}
} finally {
if (planContext != null) {
this.getContext().getTransactionServer().suspend(planContext);
}
}
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class ProcedurePlan method pullBatch.
protected TupleBatch pullBatch() {
TupleBatch batch = null;
if (this.batchRows != null) {
batch = new TupleBatch(this.beginBatch, this.batchRows);
beginBatch += this.batchRows.size();
} else {
batch = new TupleBatch(this.beginBatch, Collections.EMPTY_LIST);
}
batch.setTerminationFlag(this.lastBatch);
// Reset batch state
this.batchRows = null;
this.lastBatch = false;
// Return batch
return batch;
}
Aggregations