/** * Pro-actively pull batches for later use. * There are unfortunately quite a few cases to cover here. */ protected void prefetch(long limit) throws TeiidComponentException, TeiidProcessingException { if (!open) { return; } if (this.buffer == null) { if (this.sortUtility != null) { return; } if (this.iterator != null) { ((BatchIterator)this.iterator).readAhead(limit); return; } if (source.hasBuffer()) { this.buffer = source.getBuffer(-1); return; } if (collector == null) { collector = new BatchCollector(source, source.getBufferManager(), source.getContext(), false); } if (collector.getTupleBuffer() != null && collector.getTupleBuffer().getManagedRowCount() >= limit) { return; } this.buffer = collector.collectTuples(true); } }
@Test public void testReadAhead() throws Exception { BatchIterator bi = new BatchIterator(new FakeRelationalNode(1, new List[] { Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), Arrays.asList(1), }, 2)); BufferManager bm = BufferManagerFactory.getStandaloneBufferManager(); TupleBuffer tb = bm.createTupleBuffer(Arrays.asList(new ElementSymbol("x", null, DataTypeManager.DefaultDataClasses.INTEGER)), "test", TupleSourceType.PROCESSOR); bi.setBuffer(tb, false); //$NON-NLS-1$ bi.nextTuple(); assertEquals(1, bi.available()); assertEquals(2, bi.getBuffer().getRowCount()); bi.readAhead(100); assertEquals(4, bi.getBuffer().getRowCount()); //shouldn't keep reading bi.readAhead(3); assertEquals(4, bi.getBuffer().getRowCount()); bi.readAhead(5); assertEquals(6, bi.getBuffer().getRowCount()); bi.readAhead(8); //does nothing for (int i = 0; i < 5; i++) { assertNotNull(bi.nextTuple()); } assertNull(bi.nextTuple()); }
/** * Pro-actively pull batches for later use. * There are unfortunately quite a few cases to cover here. */ protected void prefetch(long limit) throws TeiidComponentException, TeiidProcessingException { if (!open) { return; } if (this.buffer == null) { if (this.sortUtility != null) { return; } if (this.iterator != null) { ((BatchIterator)this.iterator).readAhead(limit); return; } if (source.hasBuffer()) { this.buffer = source.getBuffer(-1); return; } if (collector == null) { collector = new BatchCollector(source, source.getBufferManager(), source.getContext(), false); } if (collector.getTupleBuffer() != null && collector.getTupleBuffer().getManagedRowCount() >= limit) { return; } this.buffer = collector.collectTuples(true); } }
assertEquals(1, bi.available()); assertEquals(0, bi.getBuffer().getRowCount()); bi.readAhead(100); assertEquals(4, bi.getBuffer().getRowCount()); bi.readAhead(2); assertEquals(4, bi.getBuffer().getRowCount()); bi.readAhead(5); assertEquals(6, bi.getBuffer().getRowCount()); bi.readAhead(8); //does nothing for (int i = 0; i < 6; i++) { assertNotNull(bi.nextTuple());
/** * Pro-actively pull batches for later use. * There are unfortunately quite a few cases to cover here. */ protected void prefetch(long limit) throws TeiidComponentException, TeiidProcessingException { if (!open) { return; } if (this.buffer == null) { if (this.sortUtility != null) { return; } if (this.iterator != null) { ((BatchIterator)this.iterator).readAhead(limit); return; } if (source.hasBuffer()) { this.buffer = source.getBuffer(-1); return; } if (collector == null) { collector = new BatchCollector(source, source.getBufferManager(), source.getContext(), false); } if (collector.getTupleBuffer() != null && collector.getTupleBuffer().getManagedRowCount() >= limit) { return; } this.buffer = collector.collectTuples(true); } }
assertEquals(0, bi.getBuffer().getManagedRowCount()); bi.readAhead(3); assertEquals(2, bi.getBuffer().getManagedRowCount()); for (int i = 0; i < 4; i++) {