@Override public TupleBatch nextBatch() throws BlockedException, TeiidComponentException, TeiidProcessingException { TupleBatch tupleBatch = new TupleBatch(1, new List[] {Arrays.asList(0)}); tupleBatch.setTerminationFlag(true); return tupleBatch; }
/** * For debugging purposes - all intermediate batches should go through this * method so we can easily trace data flow through the plan. * @param batch Batch being sent */ private void recordBatch(TupleBatch batch) { if (!LogManager.isMessageToBeRecorded(org.teiid.logging.LogConstants.CTX_DQP, MessageLevel.TRACE)) { return; } // Print summary StringBuffer str = new StringBuffer(); str.append(getClassName()); str.append("("); //$NON-NLS-1$ str.append(getID()); str.append(") sending "); //$NON-NLS-1$ str.append(batch); str.append("\n"); //$NON-NLS-1$ // Print batch contents for (long row = batch.getBeginRow(); row <= batch.getEndRow(); row++) { str.append("\t").append(row).append(": ").append(batch.getTuple(row)).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } LogManager.logTrace(org.teiid.logging.LogConstants.CTX_DQP, str.toString()); }
@Override public List<Object> nextTuple() throws TeiidComponentException, TeiidProcessingException { while (true) { if(sourceBatch == null) { // Read next batch sourceBatch = sourceNode.nextBatch(); } if(sourceBatch.getRowCount() > 0 && sourceRow <= sourceBatch.getEndRow()) { // Evaluate expressions needed for grouping List tuple = sourceBatch.getTuple(sourceRow); tuple = updateTuple(tuple); sourceRow++; return tuple; } // Check for termination condition if(sourceBatch.getTerminationFlag()) { sourceBatch = null; return null; } sourceBatch = null; } }
@Override protected boolean hasNextCommand() { return !this.currentBatch.getTerminationFlag() || batchRow <= this.currentBatch.getEndRow(); }
/** * Flush the batch by giving it to the buffer manager. */ private void flushBatch(TupleBatch batch) throws TeiidComponentException, TeiidProcessingException { if (batch.getRowCount() == 0 && batch.getTermination() == TupleBatch.NOT_TERMINATED) { return; } flushBatchDirect(batch, true); }
if ((this.begin > (batch != null?batch.getEndRow():this.resultsBuffer.getRowCount()) && !doneProducingBatches) || (this.transactionState == TransactionState.ACTIVE) || (returnsUpdateCount && !doneProducingBatches)) { return result; if (batch == null || !(batch.containsRow(this.begin) || (batch.getTerminationFlag() && batch.getEndRow() <= this.begin))) { if (savedBatch != null && savedBatch.containsRow(this.begin)) { batch = savedBatch; } else { for (int i = 1; i < batches && batch.getRowCount() + resultsBuffer.getBatchSize() <= count && !batch.getTerminationFlag(); i++) { TupleBatch next = resultsBuffer.getBatch(batch.getEndRow() + 1); if (next.getRowCount() == 0) { break; first = false; TupleBatch old = batch; batch = new TupleBatch(batch.getBeginRow(), new ResizingArrayList<List<?>>(batch.getTuples())); batch.setTermination(old.getTermination()); batch.getTuples().addAll(next.getTuples()); batch.setTermination(next.getTermination()); if (batch.getRowCount() > count) { long beginRow = isForwardOnly()?begin:Math.min(this.begin, batch.getEndRow() - count + 1); long endRow = Math.min(beginRow + count - 1, batch.getEndRow()); boolean last = false; if (endRow == batch.getEndRow()) { last = batch.getTerminationFlag(); } else if (isForwardOnly()) {
result.setRowOffset(rowOffset); if (result.getTerminationFlag()) { result.setTermination(TupleBatch.ITERATION_TERMINATED); List<Object> terminationTuple = Arrays.asList(new Object[this.getOutputElements().size()]); result.getTuples().add(terminationTuple); this.context.getTupleSourceCache().close(); this.processPlan.close(); rowOffset = result.getEndRow() + 1; if(result.getTermination() != TupleBatch.NOT_TERMINATED) { if (result.getTerminationFlag()) { done = true; if (result.getRowCount() > 0) { break;
currentBatch = new TupleBatch(1, EMPTY_TUPLE); currentBatch.setTerminationFlag(true); }else{ currentBatch = this.getChildren()[0].nextBatch(); while (currentRow <= currentBatch.getEndRow() && !isBatchFull()) { List<?> tuple = currentBatch.getTuple(currentRow); if (currentRow > currentBatch.getEndRow()) { if(currentBatch.getTerminationFlag()) { terminateBatches();
@Test public void testMultipleBatches() throws Exception { FakeProcessorPlan[] plans = new FakeProcessorPlan[4]; for (int i = 0; i < plans.length; i++) { TupleBatch last = new TupleBatch(2, Arrays.asList(Arrays.asList(1))); last.setTerminationFlag(true); plans[i] = new FakeProcessorPlan(Arrays.asList(Command.getUpdateCommandSymbol()), Arrays.asList(new TupleBatch(1, Arrays.asList(Arrays.asList(1))), BlockedException.INSTANCE, last)); } BatchedUpdatePlan plan = new BatchedUpdatePlan(Arrays.asList(plans), plans.length*2, null, false); plan.initialize(new CommandContext(), null, null); plan.open(); // First plan may or may not be opened, but all subsequent plans should not be opened. for (int i = 1; i < plans.length; i++) { assertFalse(plans[i].isOpened()); } for (int i = 0; i < 4; i++) { try { plan.nextBatch(); fail(); } catch (BlockedException e) { } } TupleBatch batch = plan.nextBatch(); assertEquals(8, batch.getRowCount()); assertTrue(batch.getTerminationFlag()); }
/** * Adds the given batch preserving row offsets. * @param batch * @throws TeiidComponentException */ public void addTupleBatch(TupleBatch batch, boolean save) throws TeiidComponentException { setRowCount(batch.getBeginRow() - 1); List<List<?>> tuples = batch.getTuples(); if (save) { for (int i = 0; i < batch.getRowCount(); i++) { addTuple(tuples.get(i)); } } else { //add the lob references only, since they may still be referenced later if (isLobs()) { for (int i = 0; i < batch.getRowCount(); i++) { lobManager.updateReferences(tuples.get(i), ReferenceMode.CREATE); } } } }
/** * @see org.teiid.query.processor.ProcessorPlan#nextBatch() */ public TupleBatch nextBatch() throws BlockedException, TeiidComponentException { if(this.batches == null || this.batches.size() == 0 || batchIndex >= this.batches.size()) { // Return empty terminator batch TupleBatch batch = new TupleBatch(nextBatchRow, Collections.EMPTY_LIST); batch.setTerminationFlag(true); return batch; } Object nextReturn = this.batches.get(batchIndex); batchIndex++; if(nextReturn instanceof TupleBatch) { TupleBatch batch = (TupleBatch) nextReturn; nextBatchRow = nextBatchRow + batch.getRowCount(); return batch; } throw (TeiidComponentException) nextReturn; }
@Test public void testOffsetNoRows() throws Exception { LimitNode node = getOffsetNode(100, new FakeRelationalNode(2, getRows(0), 50)); TupleBatch batch = node.nextBatch(); assertNotNull(batch); assertEquals(0, batch.getRowCount()); assertTrue(batch.getTerminationFlag()); }
private void process(List[] expectedResults) throws TeiidComponentException, TeiidProcessingException { join.open(); int currentRow = 1; while(true) { try { TupleBatch batch = join.nextBatch(); for(;currentRow <= batch.getEndRow(); currentRow++) { List tuple = batch.getTuple(currentRow); assertEquals("Rows don't match at " + currentRow, expectedResults[currentRow-1], tuple); //$NON-NLS-1$ } if(batch.getTerminationFlag()) { break; } } catch(BlockedException e) { // ignore and retry } } assertEquals(expectedResults.length, currentRow - 1); join.close(); }
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 long available() { if (batch != null && batch.containsRow(getCurrentIndex())) { return batch.getEndRow() - getCurrentIndex() + 1; } return 0; }
protected List<?> getCurrentTuple() throws TeiidComponentException, BlockedException, TeiidProcessingException { if (available() > 0) { //if (forwardOnly) { long row = getCurrentIndex(); if (batch == null || !batch.containsRow(row)) { batch = getBatch(row); } return batch.getTuple(row); //} //TODO: determine if we should directly hold a soft reference here //return getRow(currentRow); } batch = null; return finalRow(); }
@Override public TupleBatch nextBatchDirect() throws BlockedException, TeiidComponentException, TeiidProcessingException { TupleBatch tb = super.nextBatchDirect(); tb.setRowOffset(tb.getBeginRow() + 3); return tb; }
public boolean containsRow(long row) { return rowOffset <= row && getEndRow() >= row; }
private void helpTestNextBatch(int[] commandsPerPlan) throws Exception { List plans = new ArrayList(commandsPerPlan.length); int totalCommands = 0; for (int i = 0; i < commandsPerPlan.length; i++) { totalCommands += commandsPerPlan[i]; plans.add(new FakeProcessorPlan(commandsPerPlan[i])); } BatchedUpdatePlan plan = new BatchedUpdatePlan(plans, totalCommands, null, false); plan.initialize(new CommandContext(), null, null); TupleBatch batch = plan.nextBatch(); assertEquals(totalCommands, batch.getRowCount()); for (int i = 1; i <= totalCommands; i++) { assertEquals(new Integer(1), batch.getTuple(i).get(0)); } }
while (rowCount > rowLimit) { last = this.getBatch(rowCount); Long id = this.batches.remove(last.getBeginRow()); if (id != null) { this.manager.remove(id); for (List<?> tuple : last.getTuples()) { this.lobManager.updateReferences(tuple, ReferenceMode.REMOVE); rowCount = last.getBeginRow() - 1; List<List<?>> tuples = last.getTuples(); int i = 0; while (rowCount < rowLimit) {