Search in sources :

Example 1 with SortUtility

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();
        }
    }
}
Also used : SortUtility(org.teiid.query.processor.relational.SortUtility) TupleBufferTupleSource(org.teiid.common.buffer.TupleBuffer.TupleBufferTupleSource) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleSource(org.teiid.common.buffer.TupleSource) TupleBuffer(org.teiid.common.buffer.TupleBuffer) CollectionTupleSource(org.teiid.query.processor.CollectionTupleSource) TupleBrowser(org.teiid.common.buffer.TupleBrowser)

Aggregations

TupleBrowser (org.teiid.common.buffer.TupleBrowser)1 TupleBuffer (org.teiid.common.buffer.TupleBuffer)1 TupleBufferTupleSource (org.teiid.common.buffer.TupleBuffer.TupleBufferTupleSource)1 TupleSource (org.teiid.common.buffer.TupleSource)1 CollectionTupleSource (org.teiid.query.processor.CollectionTupleSource)1 SortUtility (org.teiid.query.processor.relational.SortUtility)1