@Override protected void tuplePassed(List tuple) throws ExpressionEvaluationException, BlockedException, TeiidComponentException { browser.removed(); deleteTuple(tuple); }
@Override public void closeSource() { if (updatable) { lock.readLock().unlock(); } bm.releaseBuffers(reserved); reserved = 0; browser.closeSource(); }
/** * Notify the browser that the last value was deleted. * @throws TeiidComponentException */ public void removed() throws TeiidComponentException { if (readOnly) { throw new AssertionError("read only"); //$NON-NLS-1$ } index-=getOffset(); List<?> lowerBound = values.remove(index); //check if the page has been removed if (page != null && page.managedBatch == null && page.values == null) { setPageAfterRemove(lowerBound); } if (index == values.size() && page != null) { boolean search = false; if (direction) { search = page.next == null; } else { search = page.prev == null; } if (search) { setPageAfterRemove(lowerBound); } } }
private boolean setPage(List<?> lowerBound) throws TeiidComponentException { this.tree.find(lowerBound, getPlaces()); SearchResult sr = places.get(places.size() - 1); page = sr.page; index = sr.index; boolean result = true; if (index < 0) { result = false; index = -index - 1; } setValues(sr.values); return result; }
List<?> newValue = valueSet.nextTuple(); if (newValue == null) { resetState(); return null; init(cachedBound, newValue, true); inPartial = true; continue; resetState(); return null; resetState(); return null; resetState(); if (!setPage(newValue)) { continue; setValues(page.getValues()); if (direction) { index = 0; index+=getOffset(); return result; resetState(); if (direction) { page = page.next;
@Test public void testTupleBrowserRemove() throws Exception { BufferManagerImpl bm = BufferManagerFactory.getTestBufferManager(1, 1); ElementSymbol e1 = new ElementSymbol("x"); e1.setType(Integer.class); ElementSymbol e2 = new ElementSymbol("x"); e2.setType(Integer.class); List<ElementSymbol> elements = Arrays.asList(e1, e2); STree map = bm.createSTree(elements, "1", 2); map.insert(Arrays.asList(1, 1), InsertMode.NEW, -1); TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(1)).iterator()), true, false); assertNotNull(tb.nextTuple()); tb.removed(); assertEquals(Integer.valueOf(0), tb.getValueCount()); }
if (lowerBound != null) { lowerBound.addAll(Collections.nCopies(tree.getKeyLength() - lowerBound.size(), null)); setPage(lowerBound); } else { page = tree.header[0]; valid = false; this.tree.find(upperBound, getPlaces()); SearchResult upper = places.get(places.size() - 1); bound = upper.page; setValues(upper.values); setValues(bound.getValues());
@Override protected void tuplePassed(List tuple) throws BlockedException, TeiidComponentException, TeiidProcessingException { List<Object> newTuple = new ArrayList<Object>(tuple); for (Map.Entry<ElementSymbol, Expression> entry : update.getClauseMap().entrySet()) { newTuple.set(columnMap.get(entry.getKey()), eval.evaluate(entry.getValue(), tuple)); } validateNotNull(newTuple); if (primaryKeyChangePossible) { browser.removed(); deleteTuple(tuple); if (changeSet == null) { changeSet = bm.createTupleBuffer(columns, sessionID, TupleSourceType.PROCESSOR); } changeSet.addTuple(newTuple); } else { browser.update(newTuple); } }
@Test public void testSearch() throws TeiidComponentException, TeiidProcessingException { //due to buffering changes we need to hold this in memory directly rather than serialize it out as that will lead to GC overhead errors BufferManagerImpl bm = BufferManagerFactory.getTestBufferManager(Integer.MAX_VALUE, 1); ElementSymbol e1 = new ElementSymbol("x"); e1.setType(Integer.class); ElementSymbol e2 = new ElementSymbol("x"); e2.setType(Integer.class); List elements = Arrays.asList(e1, e2); STree map = bm.createSTree(elements, "1", 2); int size = 1<<16; for (int i = 0; i < size; i++) { assertNull(map.insert(Arrays.asList(i, i), InsertMode.NEW, -1)); assertEquals(i + 1, map.getRowCount()); } map.compact(); for (int i = 0; i < size; i++) { TupleBrowser tb = new TupleBrowser(map, new CollectionTupleSource(Collections.singletonList(Arrays.asList(i)).iterator()), true); assertNotNull(tb.nextTuple()); assertNull(tb.nextTuple()); } }
TupleBrowser createTupleBrowser(NullOrder nullOrder, boolean readOnly) throws TeiidComponentException { boolean direction = OrderBy.ASC; if (ordering != null) { LogManager.logDetail(LogConstants.CTX_DQP, "Using index for ordering"); //$NON-NLS-1$ direction = ordering; } if (valueTs != null) { LogManager.logDetail(LogConstants.CTX_DQP, "Using index value set"); //$NON-NLS-1$ return new TupleBrowser(this.table.getTree(), valueTs, direction, readOnly); } if (!valueSet.isEmpty()) { LogManager.logDetail(LogConstants.CTX_DQP, "Using index value set"); //$NON-NLS-1$ sortValueSet(direction, nullOrder); CollectionTupleSource cts = new CollectionTupleSource(valueSet.iterator()); return new TupleBrowser(this.table.getTree(), cts, direction, readOnly); } if (lower != null || upper != null) { LogManager.logDetail(LogConstants.CTX_DQP, "Using index for range query", lower, upper); //$NON-NLS-1$ } return new TupleBrowser(this.table.getTree(), lower, upper, direction, readOnly); }
@Override public List<?> nextTuple() throws TeiidComponentException, TeiidProcessingException { for (;;) { List<?> next = browser.nextTuple(); if (next == null) { bm.releaseBuffers(reserved); reserved = 0; return null; } if (condition != null && !eval.evaluate(condition, next)) { continue; } if (project) { next = RelationalNode.projectTuple(indexes, next); } return next; } }
private void setPageAfterRemove(List<?> lowerBound) throws TeiidComponentException, AssertionError { //navigate to the current position if (!setPage(lowerBound)) { throw new AssertionError("Expected lowerBound to still exist"); //$NON-NLS-1$ } //remove the tuple from the iteration set, it will be removed from the tree by //an external call values.remove(index); }
public void reset(TupleSource ts) throws TeiidComponentException { this.valueSet = ts; resetState(); }
/** * Perform an in-place update of the tuple just returned by the next method * WARNING - this must not change the key value * @param tuple * @throws TeiidComponentException */ public void update(List<?> tuple) throws TeiidComponentException { if (readOnly) { throw new AssertionError("read only"); //$NON-NLS-1$ } values.set(index - getOffset(), tuple); updated = true; }
/** * Construct a range based browser * @param sTree * @param lowerBound * @param upperBound * @param direction * @throws TeiidComponentException */ public TupleBrowser(STree sTree, List<Object> lowerBound, List<Object> upperBound, boolean direction, boolean readOnly) throws TeiidComponentException { this.tree = sTree; this.direction = direction; this.readOnly = readOnly; init(lowerBound, upperBound, false); }
List<?> newValue = valueSet.nextTuple(); if (newValue == null) { resetState(); return null; init(cachedBound, newValue, true); inPartial = true; continue; resetState(); return null; resetState(); return null; resetState(); if (!setPage(newValue)) { continue; setValues(page.getValues()); if (direction) { index = 0; index+=getOffset(); return result; resetState(); if (direction) { page = page.next;
if (lowerBound != null) { lowerBound.addAll(Collections.nCopies(tree.getKeyLength() - lowerBound.size(), null)); setPage(lowerBound); } else { page = tree.header[0]; valid = false; this.tree.find(upperBound, getPlaces()); SearchResult upper = places.get(places.size() - 1); bound = upper.page; setValues(upper.values); setValues(bound.getValues());
@Override protected void tuplePassed(List tuple) throws BlockedException, TeiidComponentException, TeiidProcessingException { List<Object> newTuple = new ArrayList<Object>(tuple); for (Map.Entry<ElementSymbol, Expression> entry : update.getClauseMap().entrySet()) { newTuple.set(columnMap.get(entry.getKey()), eval.evaluate(entry.getValue(), tuple)); } validateNotNull(newTuple); if (primaryKeyChangePossible) { browser.removed(); deleteTuple(tuple); if (changeSet == null) { changeSet = bm.createTupleBuffer(columns, sessionID, TupleSourceType.PROCESSOR); } changeSet.addTuple(newTuple); } else { browser.update(newTuple); } }