public boolean nextBuffer() throws TeiidComponentException, TeiidProcessingException { this.closeBuffer(); if (this.buffers == null || this.buffers.isEmpty()) { if (!sortUtility.isDoneReading()) { this.buffers = sortUtility.onePassSort(limited); return nextBuffer(); } return false; } this.buffer = this.buffers.remove(this.buffers.size() - 1); this.buffer.setForwardOnly(false); this.resetState(); return true; }
public TupleBuffer sort() throws TeiidComponentException, TeiidProcessingException { return sort(-1); }
@Override public Void call() throws Exception { synchronized (SortUtility.this) { if (phase == INITIAL_SORT) { sortWorking(rowLimit); } if (phase == MERGE) { doMerge(rowLimit); } } return null; } });
public TupleBuffer sort(int rowLimit) throws TeiidComponentException, TeiidProcessingException { boolean success = false; try { waitForWork(); synchronized (this) { if(this.phase == INITIAL_SORT) { initialSort(false, false, rowLimit); } if(this.phase == MERGE) { mergePhase(rowLimit); } success = true; return this.activeTupleBuffers.get(0); } } catch (BlockedException e) { success = true; throw e; } finally { if (!success) { remove(); } } }
public TupleBuffer sort(int rowLimit) throws TeiidComponentException, TeiidProcessingException { boolean success = false; try { if(this.phase == INITIAL_SORT) { initialSort(false, false, rowLimit); } if(this.phase == MERGE) { mergePhase(rowLimit); } success = true; return this.activeTupleBuffers.get(0); } catch (BlockedException e) { success = true; throw e; } finally { if (!success) { remove(); } } }
public List<TupleBuffer> onePassSort(boolean lowLatency) throws TeiidComponentException, TeiidProcessingException { boolean success = false; try { if(this.phase == INITIAL_SORT) { initialSort(true, lowLatency, -1); if (!isDoneReading()) { this.phase = INITIAL_SORT; } } for (TupleBuffer tb : activeTupleBuffers) { tb.close(); tb.setForwardOnly(false); //it is up to the caller to set the flag now } success = true; return activeTupleBuffers; } catch (BlockedException e) { success = true; throw e; } finally { if (!success) { remove(); } } }
ts = new BatchIterator(this.source); this.sortUtility = new SortUtility(ts, expressions, Collections.nCopies(expressions.size(), OrderBy.ASC), sortOption == SortOption.SORT_DISTINCT?Mode.DUP_REMOVE_SORT:Mode.SORT, this.source.getBufferManager(), this.source.getConnectionID(), source.getElements()); this.markExpressionsDistinct(sortOption == SortOption.SORT_DISTINCT && expressions.size() == this.getOuterVals().size()); if (this.buffer != null) { this.sortUtility.setWorkingBuffer(this.buffer); if (this.buffers != null || sortUtility.isDoneReading()) { return; this.buffers = sortUtility.onePassSort(limited); if (this.buffers.size() != 1 || !sortUtility.isDoneReading()) { nextBuffer(); return; this.buffers = null; } else { sorted = sortUtility.sort(); this.markExpressionsDistinct(sortUtility.isDistinct());
this.sortUtility = new SortUtility(null, sortSymbols, sortDirection, Mode.DUP_REMOVE, dependentNode.getBufferManager(), dependentNode.getConnectionID(), originalVs.getSchema()); this.sortUtility.setWorkingBuffer(originalVs.getTupleBuffer()); this.sortUtility.setNonBlocking(true); dvs = new DependentValueSource(sortUtility.sort());
private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.sortUtility == null) { TupleSource ts = null; TupleBuffer working = null; if (!getChildren()[0].hasBuffer()) { ts = new BatchIterator(getChildren()[0]); } else { working = getChildren()[0].getBuffer(-1); } this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(), getConnectionID(), getChildren()[0].getElements()); if (ts == null) { this.sortUtility.setWorkingBuffer(working); } } this.output = this.sortUtility.sort(rowLimit); if (this.outputTs == null) { this.outputTs = this.output.createIndexedTupleSource(); } this.phase = OUTPUT; }
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;
@Test public void testDistinct() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER); ElementSymbol es2 = new ElementSymbol("e2"); //$NON-NLS-1$ es2.setType(DataTypeManager.DefaultDataClasses.INTEGER); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es2), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tsid.addTuple(Arrays.asList(1, 1)); tsid.addTuple(Arrays.asList(1, 2)); tsid.close(); SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.DUP_REMOVE_SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$ su.sort(); assertFalse(su.isDistinct()); }
@Test public void testStableSort() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tsid.addTuple(Arrays.asList(1, 1)); tsid.addTuple(Arrays.asList(1, 2)); tsid.addTuple(Arrays.asList(1, 3)); tsid.close(); SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$ su.setBatchSize(1); su.setStableSort(true); TupleBuffer out = su.sort(); TupleSource ts = out.createIndexedTupleSource(); assertEquals(Arrays.asList(1,1), ts.nextTuple()); assertEquals(Arrays.asList(1,2), ts.nextTuple()); assertEquals(Arrays.asList(1,3), ts.nextTuple()); assertNull(ts.nextTuple()); }
@Test public void testSortLimit() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es1), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tsid.addTuple(Arrays.asList(4)); tsid.addTuple(Arrays.asList(3)); tsid.addTuple(Arrays.asList(2)); tsid.addTuple(Arrays.asList(1)); tsid.close(); SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$ su.setBatchSize(2); TupleBuffer out = su.sort(2); TupleSource ts = out.createIndexedTupleSource(); assertEquals(Arrays.asList(1), ts.nextTuple()); assertEquals(Arrays.asList(2), ts.nextTuple()); assertNull(ts.nextTuple()); su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$ su.setBatchSize(10); out = su.sort(2); ts = out.createIndexedTupleSource(); assertEquals(Arrays.asList(1), ts.nextTuple()); assertEquals(Arrays.asList(2), ts.nextTuple()); assertNull(ts.nextTuple()); }
ArrayList<SortedSublist> sublists = new ArrayList<SortedSublist>(activeTupleBuffers.size()); TupleBuffer merged = createTupleBuffer(); sortedSublist.its.setNoBlocking(true); sortedSublist.index = i; incrementWorkingTuple(sublists, sortedSublist); SortedSublist sortedSublist = sublists.remove(sublists.size() - 1); merged.addTuple(sortedSublist.tuple); incrementWorkingTuple(sublists, sortedSublist);
@Test public void testOnePass() throws Exception { ElementSymbol es1 = new ElementSymbol("e1"); //$NON-NLS-1$ es1.setType(DataTypeManager.DefaultDataClasses.INTEGER); ElementSymbol es2 = new ElementSymbol("e2"); //$NON-NLS-1$ es2.setType(DataTypeManager.DefaultDataClasses.INTEGER); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TupleBuffer tsid = bm.createTupleBuffer(Arrays.asList(es1, es2), "test", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tsid.addTuple(Arrays.asList(1, 1)); tsid.addTuple(Arrays.asList(1, 2)); tsid.close(); SortUtility su = new SortUtility(tsid.createIndexedTupleSource(), Arrays.asList(es1), Arrays.asList(Boolean.TRUE), Mode.SORT, bm, "test", tsid.getSchema()); //$NON-NLS-1$ List<TupleBuffer> buffers = su.onePassSort(true); assertEquals(1, buffers.size()); assertTrue(!buffers.get(0).isForwardOnly()); }
this.workingBuffer = createTupleBuffer(); workAsync(rowLimit, cc); sortWorking(rowLimit);
this.sortUtility = new SortUtility(getGroupSortTupleSource(), removeDuplicates?Mode.DUP_REMOVE_SORT:Mode.SORT, getBufferManager(), getConnectionID(), new ArrayList<Expression>(collectedExpressions.keySet()), sortTypes, nullOrdering, sortIndexes); this.phase = SORT;
public SortUtility(TupleSource sourceID, Mode mode, BufferManager bufferMgr, String groupName, List<? extends Expression> schema, List<Boolean> sortTypes, List<NullOrdering> nullOrderings, int[] cols) { init(sourceID, mode, bufferMgr, groupName, schema, sortTypes, nullOrderings, cols); }
while (!this.notSortedSource.getSortUtility().isDoneReading() || this.notSortedSource.hasBuffer()) { if (!this.notSortedSource.hasBuffer()) { this.notSortedSource.nextBuffer();
TupleBuffer sublist = createTupleBuffer(); activeTupleBuffers.add(sublist); if (this.mode == Mode.SORT) { activeTupleBuffers.add(createTupleBuffer());