@Override protected TupleBatch getBatch(long row) throws TeiidComponentException { return TupleBuffer.this.getBatch(row); }
private void getTupleBufferState(ObjectOutputStream out, TupleBuffer buffer) throws TeiidComponentException, IOException { out.writeLong(buffer.getRowCount()); out.writeInt(buffer.getBatchSize()); out.writeObject(buffer.getTypes()); for (int row = 1; row <= buffer.getRowCount(); row+=buffer.getBatchSize()) { TupleBatch b = buffer.getBatch(row); BatchSerializer.writeBatch(out, buffer.getTypes(), b.getTuples()); } }
@Override protected TupleBatch getBatch(long row) throws TeiidComponentException { return TupleBuffer.this.getBatch(row); }
private void getTupleBufferState(ObjectOutputStream out, TupleBuffer buffer) throws TeiidComponentException, IOException { out.writeLong(buffer.getRowCount()); out.writeInt(buffer.getBatchSize()); out.writeObject(buffer.getTypes()); for (int row = 1; row <= buffer.getRowCount(); row+=buffer.getBatchSize()) { TupleBatch b = buffer.getBatch(row); BatchSerializer.writeBatch(out, buffer.getTypes(), b.getTuples()); } }
@Override protected TupleBatch getBatch(long row) throws TeiidComponentException { return TupleBuffer.this.getBatch(row); }
private void getTupleBufferState(ObjectOutputStream out, TupleBuffer buffer) throws TeiidComponentException, IOException { out.writeLong(buffer.getRowCount()); out.writeInt(buffer.getBatchSize()); out.writeObject(buffer.getTypes()); for (int row = 1; row <= buffer.getRowCount(); row+=buffer.getBatchSize()) { TupleBatch b = buffer.getBatch(row); BatchSerializer.writeBatch(out, buffer.getTypes(), b.getTuples()); } }
public void addInput(List<?> tuple, CommandContext commandContext, long startFrame, long endFrame, TupleBuffer frame) throws TeiidComponentException, TeiidProcessingException { Integer nthIndex = (Integer)tuple.get(argIndexes[1]); if (nthIndex > endFrame || nthIndex < startFrame) { this.value = null; } else { this.value = frame.getBatch(nthIndex).getTuple(nthIndex).get(argIndexes[0]); } //TODO: the computation of the nth value should be done as needed, not over the whole input set }
public void addInput(List<?> tuple, CommandContext commandContext, long startFrame, long endFrame, TupleBuffer frame) throws TeiidComponentException, TeiidProcessingException { Integer nthIndex = (Integer)tuple.get(argIndexes[1]); if (nthIndex > endFrame || nthIndex < startFrame) { this.value = null; } else { this.value = frame.getBatch(nthIndex).getTuple(nthIndex).get(argIndexes[0]); } //TODO: the computation of the nth value should be done as needed, not over the whole input set }
@Override public List<?> get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(String.valueOf(index)); } try { return tb.getBatch(index+1).getTuple(index+1); } catch (TeiidComponentException e) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30483, e); } }
@Override public List<?> get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(String.valueOf(index)); } try { return tb.getBatch(index+1).getTuple(index+1); } catch (TeiidComponentException e) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30483, e); } }
@Override public List<?> get(int index) { if (index < 0 || index >= size()) { throw new IndexOutOfBoundsException(String.valueOf(index)); } try { return tb.getBatch(index+1).getTuple(index+1); } catch (TeiidComponentException e) { throw new TeiidRuntimeException(QueryPlugin.Event.TEIID30483, e); } }
@Override public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException { synchronized (tb) { if (rowNumber <= tb.getRowCount()) { return tb.getBatch(rowNumber).getTuple(rowNumber++); } if (tb.isFinal()) { return null; } List<?> row = ts.nextTuple(); if (row == null) { tb.setFinal(true); } else { tb.addTuple(row); rowNumber++; } return row; } }
@Override public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException { synchronized (tb) { if (rowNumber <= tb.getRowCount()) { return tb.getBatch(rowNumber).getTuple(rowNumber++); } if (tb.isFinal()) { return null; } List<?> row = ts.nextTuple(); if (row == null) { tb.setFinal(true); } else { tb.addTuple(row); rowNumber++; } return row; } }
@Override public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException { synchronized (tb) { if (rowNumber <= tb.getRowCount()) { return tb.getBatch(rowNumber).getTuple(rowNumber++); } if (tb.isFinal()) { return null; } List<?> row = ts.nextTuple(); if (row == null) { tb.setFinal(true); } else { tb.addTuple(row); rowNumber++; } return row; } }
@Test public void testForwardOnly() throws Exception { ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ x.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> schema = Arrays.asList(x); TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tb.setForwardOnly(true); tb.addTuple(Arrays.asList(1)); TupleBatch batch = tb.getBatch(1); assertTrue(!batch.getTerminationFlag()); assertEquals(1, batch.getBeginRow()); try { tb.getBatch(1); fail("expected exception"); //$NON-NLS-1$ } catch (AssertionError e) { } tb.addTuple(Arrays.asList(1)); tb.close(); batch = tb.getBatch(2); assertTrue(batch.getTerminationFlag()); assertEquals(2, batch.getBeginRow()); }
@Override protected List<?> finalRow() throws TeiidComponentException, TeiidProcessingException { if (this.buffer != null && this.getCurrentIndex() <= this.buffer.getRowCount()) { batch = this.buffer.getBatch(this.getCurrentIndex()); } while (available() < 1) { if (done) { return null; } batch = source.nextBatch(); done = batch.getTerminationFlag(); if (buffer != null && (!saveOnMark || mark) && !buffer.isForwardOnly()) { buffer.addTupleBatch(batch, true); } if (done && buffer != null) { this.buffer.close(); } } return getCurrentTuple(); }
@Override protected List<?> finalRow() throws TeiidComponentException, TeiidProcessingException { if (this.buffer != null && this.getCurrentIndex() <= this.buffer.getRowCount()) { batch = this.buffer.getBatch(this.getCurrentIndex()); } while (available() < 1) { if (done) { return null; } batch = source.nextBatch(); done = batch.getTerminationFlag(); if (buffer != null && (!saveOnMark || mark) && !buffer.isForwardOnly()) { buffer.addTupleBatch(batch, true); } if (done && buffer != null) { this.buffer.close(); } } return getCurrentTuple(); }
@Override protected List<?> finalRow() throws TeiidComponentException, TeiidProcessingException { if (this.buffer != null && this.getCurrentIndex() <= this.buffer.getRowCount()) { batch = this.buffer.getBatch(this.getCurrentIndex()); } while (available() < 1) { if (done) { return null; } batch = source.nextBatch(); done = batch.getTerminationFlag(); if (buffer != null && (!saveOnMark || mark) && !buffer.isForwardOnly()) { buffer.addTupleBatch(batch, true); } if (done && buffer != null) { this.buffer.close(); } } return getCurrentTuple(); }
@Test public void testTruncatePartial() throws Exception { ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ x.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> schema = Arrays.asList(x); TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tb.setBatchSize(64); for (int i = 0; i < 65; i++) { tb.addTuple(Arrays.asList(1)); } TupleBatch batch = tb.getBatch(1); assertTrue(!batch.getTerminationFlag()); assertEquals(65, tb.getManagedRowCount()); tb.truncateTo(3); assertEquals(3, tb.getManagedRowCount()); assertEquals(3, tb.getRowCount()); batch = tb.getBatch(3); }
@Test public void testTruncate() throws Exception { ElementSymbol x = new ElementSymbol("x"); //$NON-NLS-1$ x.setType(DataTypeManager.DefaultDataClasses.INTEGER); List<ElementSymbol> schema = Arrays.asList(x); TupleBuffer tb = BufferManagerFactory.getStandaloneBufferManager().createTupleBuffer(schema, "x", TupleSourceType.PROCESSOR); //$NON-NLS-1$ tb.setBatchSize(2); for (int i = 0; i < 5; i++) { tb.addTuple(Arrays.asList(1)); } TupleBatch batch = tb.getBatch(1); assertTrue(!batch.getTerminationFlag()); assertEquals(2, batch.getEndRow()); tb.close(); assertEquals(5, tb.getManagedRowCount()); tb.truncateTo(3); assertEquals(3, tb.getManagedRowCount()); assertEquals(3, tb.getRowCount()); batch = tb.getBatch(3); assertTrue(batch.getTerminationFlag()); tb.truncateTo(2); assertEquals(2, tb.getManagedRowCount()); assertEquals(2, tb.getRowCount()); batch = tb.getBatch(2); assertTrue(batch.getTerminationFlag()); }