/** Adds a key to looked up */ public Query rowKey(ByteString key) { Preconditions.checkNotNull(key, "Key can't be null."); builder.getRowsBuilder().addRowKeys(key); return this; }
.setFilter(filter) .setRows(RowSet.newBuilder() .addRowKeys(ByteStringer.wrap(key.getBytes())));
RpcExpectation expectRequest(String... keys) { for (String key : keys) { requestBuilder.getRowsBuilder().addRowKeys(ByteString.copyFromUtf8(key)); } return this; }
/** * Add a single row key to the output. This can be called multiple times with random rowKeys. * Duplicate rowKeys will result in a single response in the scan results. Results of scans also * return rows in lexicographically sorted order, and not based on the order in which row keys * were added. * @param rowKey */ public void addRowKey(byte[] rowKey) { rowSet.addRowKeys(ByteStringer.wrap(rowKey)); }
/** Adds a key to looked up */ public Query rowKey(ByteString key) { Preconditions.checkNotNull(key, "Key can't be null."); builder.getRowsBuilder().addRowKeys(key); return this; }
ByteString rowKey = rowKeys[i]; if (ByteStringComparator.INSTANCE.compare(rowKey, splitPoint) <= 0) { segment.addRowKeys(rowKey); isSegmentEmpty = false; rowKeysStart++; segment.addRowKeys(rowKeys[i]);
RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0")) .addRowKeys(ByteString.copyFromUtf8("a")) .addRowKeys(ByteString.copyFromUtf8("c")) .addRowKeys(ByteString.copyFromUtf8("0")) .addRowKeys(ByteString.copyFromUtf8("a")) .addRowKeys(ByteString.copyFromUtf8("c"))
RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("7-row-key-1")) .addRowKeys(ByteString.copyFromUtf8("2-row-key-2")) .addRowRanges( RowRange.newBuilder() splitPoints, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("2-row-key-2")) .addRowRanges( RowRange.newBuilder() .build(), RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("7-row-key-1")) .addRowRanges( RowRange.newBuilder()
@Test public void rangeExactlyFitsSplitTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("5-split")) .addRowRanges( RowRange.newBuilder() .setStartKeyOpen(ByteString.copyFromUtf8("3-split")) .setEndKeyClosed(ByteString.copyFromUtf8("5-split"))) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("3-split")) .add(ByteString.copyFromUtf8("5-split")) .build(); verifySplit( rowSet, splitPoints, null, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("5-split")) .addRowRanges( RowRange.newBuilder() .setStartKeyOpen(ByteString.copyFromUtf8("3-split")) .setEndKeyClosed(ByteString.copyFromUtf8("5-split"))) .build(), null); }
@Test public void rangeRightOfSplitTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("9-row-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyOpen(ByteString.copyFromUtf8("5-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("7-range-end"))) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("3-split")) .build(); verifySplit( rowSet, splitPoints, null, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("9-row-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyOpen(ByteString.copyFromUtf8("5-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("7-range-end"))) .build()); }
@Test public void rangeImmediatelyLeftOfSplitTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("1-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("2-range-end"))) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("2-range-end")) .build(); verifySplit( rowSet, splitPoints, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("1-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("2-range-end"))) .build(), null); }
@Test public void rangeLeftOfSplitTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("1-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("2-range-end"))) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("3-split")) .build(); verifySplit( rowSet, splitPoints, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("1-range-start")) .setEndKeyOpen(ByteString.copyFromUtf8("2-range-end"))) .build(), null); }
@Test public void splitMultipleKeysTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("1-beforeSplit")) .addRowKeys(ByteString.copyFromUtf8("2-onSplit")) .addRowKeys(ByteString.copyFromUtf8("3-afterSplit")) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("2-onSplit")) .build(); verifySplit( rowSet, splitPoints, RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("1-beforeSplit")) .addRowKeys(ByteString.copyFromUtf8("2-onSplit")) .build(), RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("3-afterSplit")).build()); }
@Test public void splitKeysEmptyLeft() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("5-test")) .addRowKeys(ByteString.copyFromUtf8("8-test")) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("0-split")) .add(ByteString.copyFromUtf8("6-split")) .build(); verifySplit( rowSet, splitPoints, null, RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("5-test")).build(), RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("8-test")).build()); }
@Test public void splitKeysEmptyRight() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("0-test")) .addRowKeys(ByteString.copyFromUtf8("2-test")) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE) .add(ByteString.copyFromUtf8("1-split")) .add(ByteString.copyFromUtf8("5-split")) .build(); verifySplit( rowSet, splitPoints, RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("0-test")).build(), RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("2-test")).build(), null); }
@Test public void testFromProto() { ReadRowsRequest request = ReadRowsRequest.newBuilder() .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID)) .setAppProfileId(APP_PROFILE_ID) .setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*"))) .setRows( RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("row-key")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("j")) .setEndKeyClosed(ByteString.copyFromUtf8("z")))) .build(); Query query = Query.fromProto(request); assertThat(query.toProto(requestContext)).isEqualTo(request); }
@Test public void rowKeysTest() { Query query = Query.create(TABLE_ID) .rowKey("simple-string") .rowKey(ByteString.copyFromUtf8("byte-string")); ReadRowsRequest.Builder expectedProto = expectedProtoBuilder(); expectedProto .getRowsBuilder() .addRowKeys(ByteString.copyFromUtf8("simple-string")) .addRowKeys(ByteString.copyFromUtf8("byte-string")); ReadRowsRequest actualProto = query.toProto(requestContext); assertThat(actualProto).isEqualTo(expectedProto.build()); }
@Test public void noSplitTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("a")) .addRowRanges( RowRange.newBuilder() .setStartKeyClosed(ByteString.copyFromUtf8("p")) .setEndKeyOpen(ByteString.copyFromUtf8("q"))) .build(); SortedSet<ByteString> splitPoints = ImmutableSortedSet.orderedBy(ByteStringComparator.INSTANCE).build(); verifySplit(rowSet, splitPoints, rowSet); }
@Test public void singleKeyBoundTest() { RowSet rowSet = RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("a")).build(); ByteStringRange actual = RowSetUtil.getBound(rowSet); assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endClosed("a")); }
@Test public void multiKeyBoundTest() { RowSet rowSet = RowSet.newBuilder() .addRowKeys(ByteString.copyFromUtf8("a")) .addRowKeys(ByteString.copyFromUtf8("d")) .build(); ByteStringRange actual = RowSetUtil.getBound(rowSet); assertThat(actual).isEqualTo(ByteStringRange.unbounded().startClosed("a").endClosed("d")); }