public static byte[] getNextStartRow(boolean reverse, @Nonnull byte[] rowName) { if (reverse) { return previousLexicographicName(rowName); } else { return nextLexicographicName(rowName); } }
@Nullable public static byte[] getNextStartRowUnlessTerminal(boolean reverse, @Nonnull byte[] rowName) { if (reverse) { if (isFirstRowName(rowName)) { return null; } else { return previousLexicographicName(rowName); } } else { return nextLexicographicNameInternal(rowName); } } }
/** * This will return a start and end row that will exactly contain all rows for this prefix in * reverse. * <p> * start will be on the left hand side and will be greater lexicographically */ private static Pair<byte[], byte[]> createNamesForReversePrefixScan(@Nonnull byte[] name) { Preconditions.checkNotNull(name, "name cannot be null"); Preconditions.checkArgument(name.length <= Cell.MAX_NAME_LENGTH, "name is too long"); if (name.length == 0) { return Pair.create(name, name); } byte[] startName = new byte[Cell.MAX_NAME_LENGTH]; System.arraycopy(name, 0, startName, 0, name.length); for (int i = name.length; i < startName.length; i++) { startName[i] = (byte) 0xff; } byte[] endName = RangeRequests.previousLexicographicName(name); return Pair.create(startName, endName); }
private Range createColumnRange(byte[] startColOrEmpty, byte[] endColExlusiveOrEmpty, long startTs) { ByteBuffer start = startColOrEmpty.length == 0 ? Range.UNBOUND_START : Range.startOfColumn(startColOrEmpty, startTs); ByteBuffer end = endColExlusiveOrEmpty.length == 0 ? Range.UNBOUND_END : Range.endOfColumnIncludingSentinels(RangeRequests.previousLexicographicName(endColExlusiveOrEmpty)); return Range.of(start, end); }
private KeyRange getKeyRange(byte[] startKey, byte[] endExclusive) { KeyRange keyRange = new KeyRange(batchHint); keyRange.setStart_key(startKey); if (endExclusive.length == 0) { keyRange.setEnd_key(endExclusive); } else { // We need the previous name because this is inclusive, not exclusive keyRange.setEnd_key(RangeRequests.previousLexicographicName(endExclusive)); } return keyRange; } }
private void assertNextPrevEqualsOrig(byte[] value) { Assert.assertTrue(Arrays.equals(value, RangeRequests.nextLexicographicName(RangeRequests.previousLexicographicName(value)))); Assert.assertTrue(Arrays.equals(value, RangeRequests.previousLexicographicName(RangeRequests.nextLexicographicName(value)))); } }
private RowColumnRangeIterator getColumnRangeForSingleRow(ConcurrentSkipListMap<Key, byte[]> table, byte[] row, ColumnRangeSelection columnRangeSelection, long timestamp) { Cell rowBegin; if (columnRangeSelection.getStartCol().length > 0) { rowBegin = Cell.create(row, columnRangeSelection.getStartCol()); } else { rowBegin = Cells.createSmallestCellForRow(row); } // Inclusive last cell. Cell rowEnd; if (columnRangeSelection.getEndCol().length > 0) { rowEnd = Cell.create(row, RangeRequests.previousLexicographicName(columnRangeSelection.getEndCol())); } else { rowEnd = Cells.createLargestCellForRow(row); } PeekingIterator<Entry<Key, byte[]>> entries = Iterators.peekingIterator(table.subMap( new Key(rowBegin, Long.MIN_VALUE), new Key(rowEnd, timestamp)).entrySet().iterator()); Map<Cell, Value> rowResults = new LinkedHashMap<>(); while (entries.hasNext()) { Entry<Key, byte[]> entry = entries.peek(); Key key = entry.getKey(); Iterator<Entry<Key, byte[]>> cellIter = takeCell(entries, key); getLatestVersionOfCell(row, key, cellIter, timestamp, rowResults); } return new LocalRowColumnRangeIterator(rowResults.entrySet().iterator()); }
public static byte[] getNextStartRow(boolean reverse, @Nonnull byte[] rowName) { if (reverse) { return previousLexicographicName(rowName); } else { return nextLexicographicName(rowName); } }
@Nullable public static byte[] getNextStartRowUnlessTerminal(boolean reverse, @Nonnull byte[] rowName) { if (reverse) { if (isFirstRowName(rowName)) { return null; } else { return previousLexicographicName(rowName); } } else { return nextLexicographicNameInternal(rowName); } } }
/** * This will return a start and end row that will exactly contain all rows for this prefix in * reverse. * <p> * start will be on the left hand side and will be greater lexicographically */ private static Pair<byte[], byte[]> createNamesForReversePrefixScan(@Nonnull byte[] name) { Preconditions.checkNotNull(name, "name cannot be null"); Preconditions.checkArgument(name.length <= Cell.MAX_NAME_LENGTH, "name is too long"); if (name.length == 0) { return Pair.create(name, name); } byte[] startName = new byte[Cell.MAX_NAME_LENGTH]; System.arraycopy(name, 0, startName, 0, name.length); for (int i = name.length; i < startName.length; i++) { startName[i] = (byte) 0xff; } byte[] endName = RangeRequests.previousLexicographicName(name); return Pair.create(startName, endName); }
private Range createColumnRange(byte[] startColOrEmpty, byte[] endColExlusiveOrEmpty, long startTs) { ByteBuffer start = startColOrEmpty.length == 0 ? Range.UNBOUND_START : Range.startOfColumn(startColOrEmpty, startTs); ByteBuffer end = endColExlusiveOrEmpty.length == 0 ? Range.UNBOUND_END : Range.endOfColumnIncludingSentinels(RangeRequests.previousLexicographicName(endColExlusiveOrEmpty)); return Range.of(start, end); }
private KeyRange getKeyRange(byte[] startKey, byte[] endExclusive) { KeyRange keyRange = new KeyRange(batchHint); keyRange.setStart_key(startKey); if (endExclusive.length == 0) { keyRange.setEnd_key(endExclusive); } else { // We need the previous name because this is inclusive, not exclusive keyRange.setEnd_key(RangeRequests.previousLexicographicName(endExclusive)); } return keyRange; } }
private RowColumnRangeIterator getColumnRangeForSingleRow(ConcurrentSkipListMap<Key, byte[]> table, byte[] row, ColumnRangeSelection columnRangeSelection, long timestamp) { Cell rowBegin; if (columnRangeSelection.getStartCol().length > 0) { rowBegin = Cell.create(row, columnRangeSelection.getStartCol()); } else { rowBegin = Cells.createSmallestCellForRow(row); } // Inclusive last cell. Cell rowEnd; if (columnRangeSelection.getEndCol().length > 0) { rowEnd = Cell.create(row, RangeRequests.previousLexicographicName(columnRangeSelection.getEndCol())); } else { rowEnd = Cells.createLargestCellForRow(row); } PeekingIterator<Entry<Key, byte[]>> entries = Iterators.peekingIterator(table.subMap( new Key(rowBegin, Long.MIN_VALUE), new Key(rowEnd, timestamp)).entrySet().iterator()); Map<Cell, Value> rowResults = new LinkedHashMap<>(); while (entries.hasNext()) { Entry<Key, byte[]> entry = entries.peek(); Key key = entry.getKey(); Iterator<Entry<Key, byte[]>> cellIter = takeCell(entries, key); getLatestVersionOfCell(row, key, cellIter, timestamp, rowResults); } return new LocalRowColumnRangeIterator(rowResults.entrySet().iterator()); }