use of org.teiid.query.processor.relational.SortUtility in project teiid by teiid.
the class TempTable method createTupleSource.
private TupleSource createTupleSource(final List<? extends Expression> projectedCols, final Criteria condition, OrderBy orderBy, IndexInfo ii, boolean agg) throws TeiidComponentException, TeiidProcessingException {
TupleBrowser browser = ii.createTupleBrowser(bm.getOptions().getDefaultNullOrder(), true);
TupleSource ts = new QueryTupleSource(browser, columnMap, agg ? getColumns() : projectedCols, condition);
boolean usingQueryTupleSource = false;
boolean success = false;
TupleBuffer tb = null;
try {
if (ii.ordering == null && orderBy != null) {
SortUtility sort = new SortUtility(ts, orderBy.getOrderByItems(), Mode.SORT, bm, sessionID, projectedCols);
sort.setNonBlocking(true);
tb = sort.sort();
} else if (agg) {
int count = 0;
while (ts.nextTuple() != null) {
count++;
}
success = true;
return new CollectionTupleSource(Arrays.asList(Collections.nCopies(projectedCols.size(), count)).iterator());
} else if (updatable) {
tb = bm.createTupleBuffer(projectedCols, sessionID, TupleSourceType.PROCESSOR);
List<?> next = null;
while ((next = ts.nextTuple()) != null) {
tb.addTuple(next);
}
} else {
usingQueryTupleSource = true;
success = true;
return ts;
}
tb.close();
success = true;
return tb.createIndexedTupleSource(true);
} finally {
if (!success && tb != null) {
tb.remove();
}
if (!usingQueryTupleSource) {
// ensure the buffers get released
ts.closeSource();
}
}
}
Aggregations