private static String encodeQueries(List<SliceQuery> queries) { List<String> queryStrings = new ArrayList<>(queries.size()); for (SliceQuery query : queries) { String start = Hex.bytesToHex(query.getSliceStart().as(StaticBuffer.ARRAY_FACTORY)); String end = Hex.bytesToHex(query.getSliceEnd().as(StaticBuffer.ARRAY_FACTORY)); final int limit; if (query.hasLimit()) { limit = query.getLimit(); } else { limit = -1; } queryStrings.add(String.format("%s/%s/%d", start, end, limit)); } return Joiner.on(":").join(queryStrings); }
@Override public SliceQuery updateLimit(int newLimit) { return new SliceQuery(sliceStart, sliceEnd).setLimit(newLimit); }
@Override public Iterator<Entry> getNewIterator(int newLimit) { if (newLimit>sliceQuery.getLimit()) sliceQuery = sliceQuery.updateLimit(newLimit); return getBasicIterator(); } }
public SliceQuery(final SliceQuery query) { this(query.getSliceStart(), query.getSliceEnd()); setLimit(query.getLimit()); }
protected String encodeForLog(final SliceQuery query) { return "slice[rk:" + encodeKeyForLog(query.getSliceStart()) + " -> " + encodeKeyForLog(query.getSliceEnd()) + " limit:" + query.getLimit() + "]"; }
public static boolean matches(SliceQuery query, StaticBuffer column) { return query.getSliceStart().compareTo(column)<=0 && query.getSliceEnd().compareTo(column)>0; }
public boolean subsumes(SliceQuery oth) { Preconditions.checkNotNull(oth); if (this == oth) return true; if (oth.getLimit() > getLimit()) return false; else if (!hasLimit()) //the interval must be subsumed return sliceStart.compareTo(oth.sliceStart) <= 0 && sliceEnd.compareTo(oth.sliceEnd) >= 0; else //this the result might be cutoff due to limit, the start must be the same return sliceStart.compareTo(oth.sliceStart) == 0 && sliceEnd.compareTo(oth.sliceEnd) >= 0; }
StaticBuffer start = ground.getSliceStart(); Preconditions.checkArgument(start.equals(BufferUtil.zeroBuffer(1)), "Expected start of first query to be a single 0s: %s",start); StaticBuffer end = ground.getSliceEnd(); Preconditions.checkArgument(end.equals(BufferUtil.oneBuffer(end.length())), "Expected end of first query to be all 1s: %s",end); EntryList entries = EntryList.EMPTY_LIST; if (currentResults[i]!=null && currentResults[i].key.equals(key)) { assert query.equals(currentResults[i].query); entries = currentResults[i].entries; currentResults[i]=null;
EntryRecordIterator(final SliceQuery sliceQuery, final CQLColValGetter getter, final Iterator<Row> iterator, final StaticBuffer key) { this.getter = getter; final StaticBuffer sliceEnd = sliceQuery.getSliceEnd(); this.iterator = iterator .<Tuple3<StaticBuffer, StaticBuffer, Row>> map(row -> Tuple.of( StaticArrayBuffer.of(row.getBytes(CQLKeyColumnValueStore.COLUMN_COLUMN_NAME)), StaticArrayBuffer.of(row.getBytes(CQLKeyColumnValueStore.VALUE_COLUMN_NAME)), row)) .takeWhile(tuple -> key.equals(StaticArrayBuffer.of(tuple._3.getBytes(CQLKeyColumnValueStore.KEY_COLUMN_NAME))) && !sliceEnd.equals(tuple._1)) .take(sliceQuery.getLimit()); }
@Override public void process(StaticBuffer key, Map<SliceQuery, EntryList> entries, ScanMetrics metrics) { long vertexId = getVertexId(key); assert entries.get(VERTEX_EXISTS_QUERY)!=null; if (isGhostVertex(vertexId, entries.get(VERTEX_EXISTS_QUERY))) { metrics.incrementCustom(GHOST_VERTEX_COUNT); return; } JanusGraphVertex vertex = tx.getInternalVertex(vertexId); Preconditions.checkArgument(vertex instanceof PreloadedVertex, "The bounding transaction is not configured correctly"); PreloadedVertex v = (PreloadedVertex)vertex; v.setAccessCheck(PreloadedVertex.OPENSTAR_CHECK); for (Map.Entry<SliceQuery,EntryList> entry : entries.entrySet()) { SliceQuery sq = entry.getKey(); if (sq.equals(VERTEX_EXISTS_QUERY)) continue; EntryList entryList = entry.getValue(); if (entryList.size()>=sq.getLimit()) metrics.incrementCustom(TRUNCATED_ENTRY_LISTS); v.addToQueryCache(sq.updateLimit(Query.NO_LIMIT),entryList); } job.process(v, metrics); }
public EntryList getSubset(final SliceQuery otherQuery, final EntryList otherResult) { assert otherQuery.subsumes(this); int pos = Collections.binarySearch(otherResult, sliceStart); if (pos < 0) pos = -pos - 1; final List<Entry> result = new ArrayList<>(); for (; pos < otherResult.size() && result.size() < getLimit(); pos++) { Entry e = otherResult.get(pos); if (e.getColumnAs(StaticBuffer.STATIC_FACTORY).compareTo(sliceEnd) < 0) result.add(e); else break; } return StaticArrayEntryList.of(result); }
@Override public SliceQuery setLimit(int limit) { Preconditions.checkArgument(!hasLimit()); super.setLimit(limit); return this; }
public SliceQuery getQuery(RelationCategory resultType, boolean querySystemTypes) { Preconditions.checkNotNull(resultType); StaticBuffer[] bound = getBounds(resultType, querySystemTypes); return new SliceQuery(bound[0], bound[1]); }
@Override public KeySliceQuery setLimit(int limit) { super.setLimit(limit); return this; }
private List<Entry> decodeSlice(final Map<String, AttributeValue> item) { final List<Entry> entries = new EntryBuilder(item).buildAll(); final Entry sliceStartEntry = StaticArrayEntry.of(sliceQuery.getSliceStart(), BufferUtil.emptyBuffer()); final Entry sliceEndEntry = StaticArrayEntry.of(sliceQuery.getSliceEnd(), BufferUtil.emptyBuffer()); final List<Entry> filteredEntries = new ArrayList<>(entries.size()); for (Entry entry : entries) { if (entry.compareTo(sliceStartEntry) >= 0 && entry.compareTo(sliceEndEntry) < 0) { filteredEntries.add(entry); } } return filteredEntries.subList(0, Math.min(filteredEntries.size(), sliceQuery.getLimit())); }
public FilterExpressionBuilder range(final SliceQuery slice) { this.startValue = slice.getSliceStart(); this.endValue = slice.getSliceEnd(); return this; }
@Override public Iterator<Entry> iterator() { Iterator<Entry> iterator; //If there is a limit we need to wrap the basic iterator in a LimitAdjustingIterator which ensures the right number //of elements is returned. Otherwise we just return the basic iterator. if (sliceQuery.hasLimit() && sliceQuery.getLimit()!=query.getLimit()) { iterator = new LimitAdjustingIterator(); } else { iterator = getBasicIterator(); } return iterator; }
@Override public int hashCode() { return new HashCodeBuilder().append(sliceStart).append(sliceEnd).append(getLimit()).toHashCode(); }
public static SliceQuery getQuery(int startCol, int endCol) { return new SliceQuery(BufferUtil.getIntBuffer(startCol),BufferUtil.getIntBuffer(endCol)); }