use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class TestTupleBatch method exampleBatch.
public TupleBatch exampleBatch(int rowBegin, int numRows, int numColumns) {
List rows = new ArrayList();
for (int i = 0; i < numRows; i++) {
List row = new ArrayList();
for (int j = 0; j < numColumns; j++) {
// $NON-NLS-1$ //$NON-NLS-2$
row.add("data-" + (rowBegin + i) + "-" + j);
}
rows.add(row);
}
return new TupleBatch(rowBegin, rows);
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class SubqueryAwareEvaluator method evaluateProcedure.
/**
* Implements procedure function handling.
* TODO: cache results
*/
@Override
protected Object evaluateProcedure(Function function, List<?> tuple, Object[] values) throws TeiidComponentException, TeiidProcessingException {
QueryProcessor qp = null;
List<?> key = Arrays.asList(function, Arrays.asList(values));
if (procedureState != null) {
qp = this.procedureState.get(key);
}
if (qp == null) {
String args = Collections.nCopies(values.length, '?').toString().substring(1);
args = args.substring(0, args.length() - 1);
String fullName = function.getFunctionDescriptor().getFullName();
// $NON-NLS-1$
String call = String.format("call %1$s(%2$s)", fullName, args);
qp = this.context.getQueryProcessorFactory().createQueryProcessor(call, fullName, this.context, values);
if (this.procedureState == null) {
this.procedureState = new HashMap<List<?>, QueryProcessor>();
}
this.procedureState.put(key, qp);
}
// just in case validate the rows being returned
TupleBatch tb = qp.nextBatch();
TupleBatch next = tb;
while (!next.getTerminationFlag()) {
if (next.getEndRow() >= 2) {
break;
}
next = qp.nextBatch();
}
if (next.getEndRow() >= 2) {
throw new ExpressionEvaluationException(QueryPlugin.Event.TEIID30345, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30345, function));
}
Object result = null;
if (next.getRowCount() > 0) {
result = next.getTuples().get(0).get(0);
}
this.procedureState.remove(key);
qp.closeProcessing();
return result;
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class TextTableNode method nextBatchDirect.
@Override
protected synchronized TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (reader == null) {
initReader();
}
if (reader == null) {
terminateBatches();
return pullBatch();
}
if (isLastBatch()) {
return pullBatch();
}
if (isBatchFull()) {
TupleBatch result = pullBatch();
// read ahead
processAsynch();
return result;
}
unwrapException(asynchException);
processAsynch();
if (this.getContext().getWorkItem() == null) {
// this is for compatibility with engine tests that are below the level of using the work item
synchronized (this) {
while (running) {
try {
this.wait();
} catch (InterruptedException e) {
throw new TeiidRuntimeException(e);
}
}
}
}
// $NON-NLS-1$
throw BlockedException.block("Blocking on results from file processing.");
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class LimitNode method nextBatchDirect.
protected TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
// Can throw BlockedException
TupleBatch batch = null;
if (limit == 0) {
this.terminateBatches();
return pullBatch();
}
// If we haven't reached the offset, then skip rows/batches
if (offsetPhase) {
while (rowCounter <= offset) {
// Can throw BlockedException
batch = getChildren()[0].nextBatch();
rowCounter += batch.getRowCount();
if (batch.getTerminationFlag()) {
break;
}
}
List<List<?>> tuples = null;
if (rowCounter > offset) {
List<List<?>> originalTuples = batch.getTuples();
int rowsToKeep = rowCounter - offset;
tuples = new ArrayList<List<?>>(originalTuples.subList(batch.getRowCount() - rowsToKeep, batch.getRowCount()));
} else {
tuples = Collections.emptyList();
}
TupleBatch resultBatch = new TupleBatch(1, tuples);
resultBatch.setTerminationFlag(batch.getTerminationFlag());
batch = resultBatch;
offsetPhase = false;
rowCounter = 0;
} else {
// Can throw BlockedException
batch = getChildren()[0].nextBatch();
}
List<List<?>> tuples = null;
if (limit < 0 || rowCounter + batch.getRowCount() <= limit) {
// Passthrough
tuples = batch.getTuples();
} else {
// Partial batch
List<List<?>> originalTuples = batch.getTuples();
tuples = new ArrayList<List<?>>(originalTuples.subList(0, limit - rowCounter));
}
TupleBatch resultBatch = new TupleBatch(rowCounter + 1, tuples);
rowCounter += resultBatch.getRowCount();
if (rowCounter == limit || batch.getTerminationFlag()) {
resultBatch.setTerminationFlag(true);
}
return resultBatch;
}
use of org.teiid.common.buffer.TupleBatch in project teiid by teiid.
the class ProjectNode method nextBatchDirect.
public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (currentBatch == null) {
// one batch with one row
if (this.getChildren()[0] == null) {
currentBatch = new TupleBatch(1, EMPTY_TUPLE);
currentBatch.setTerminationFlag(true);
} else {
currentBatch = this.getChildren()[0].nextBatch();
}
// Check for no project needed and pass through
if (!needsProject) {
TupleBatch result = currentBatch;
currentBatch = null;
return result;
}
}
while (currentRow <= currentBatch.getEndRow() && !isBatchFull()) {
List<?> tuple = currentBatch.getTuple(currentRow);
List<Object> projectedTuple = new ArrayList<Object>(selectSymbols.size());
// Walk through symbols
for (int i = 0; i < expressions.size(); i++) {
Expression symbol = expressions.get(i);
updateTuple(symbol, i, tuple, projectedTuple);
}
// Add to batch
addBatchRow(projectedTuple);
currentRow++;
}
if (currentRow > currentBatch.getEndRow()) {
if (currentBatch.getTerminationFlag()) {
terminateBatches();
}
currentBatch = null;
}
return pullBatch();
}
Aggregations