com.google.cloud.bigtable.data.v2.models.Query类的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(257)

本文整理了Java中com.google.cloud.bigtable.data.v2.models.Query类的一些代码示例,展示了Query类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query类的具体详情如下:
包路径:com.google.cloud.bigtable.data.v2.models.Query
类名称:Query

Query介绍

[英]A simple wrapper to construct a query for the ReadRows RPC.
[中]一个简单的包装器,用于构造ReadRows RPC的查询。

代码示例

代码示例来源:origin: googleapis/google-cloud-java

  1. Query query = Query.create(tableId).rowKey(rowKey);
  2. if (filter != null) {
  3. query = query.filter(filter);

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void testLimitAdded() {
  3. ReadRowsFirstCallable<Row> callable = new ReadRowsFirstCallable<>(innerCallable);
  4. innerResult.set(null);
  5. callable.call(Query.create("fake-table"));
  6. Truth.assertThat(innerQuery.getValue().toProto(REQUEST_CONTEXT))
  7. .isEqualTo(Query.create("fake-table").limit(1).toProto(REQUEST_CONTEXT));
  8. }

代码示例来源:origin: googleapis/google-cloud-java

  1. public Query prefix(String prefix) {
  2. return range(ByteStringRange.prefix(prefix));
  3. }

代码示例来源:origin: googleapis/google-cloud-java

  1. /**
  2. * Adds a range to be looked up.
  3. *
  4. * @param start The beginning of the range (inclusive). Can be null to represent negative
  5. * infinity.
  6. * @param end The end of the range (exclusive). Can be null to represent positive infinity.
  7. */
  8. public Query range(String start, String end) {
  9. return range(wrapKey(start), wrapKey(end));
  10. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void serializationTest() throws IOException, ClassNotFoundException {
  3. Query expected = Query.create(TABLE_ID).filter(FILTERS.key().regex(".*"));
  4. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  5. ObjectOutputStream oos = new ObjectOutputStream(bos);
  6. oos.writeObject(expected);
  7. oos.close();
  8. ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
  9. Query actual = (Query) ois.readObject();
  10. assertThat(actual.toProto(requestContext)).isEqualTo(expected.toProto(requestContext));
  11. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void proxyReadRowAsyncTest() {
  3. bigtableDataClient.readRowAsync("fake-table", ByteString.copyFromUtf8("fake-row-key"));
  4. Mockito.verify(mockReadRowCallable)
  5. .futureCall(Query.create("fake-table").rowKey("fake-row-key"));
  6. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void shardTestKeyOffsets() {
  3. Query query = Query.create(TABLE_ID).range("a", "z");
  4. KeyOffset.create(ByteString.EMPTY, 100));
  5. List<Query> subQueries = query.shard(keyOffsets);
  6. assertThat(subQueries.get(0).toProto(requestContext))
  7. .isEqualTo(
  8. ReadRowsRequest.newBuilder()
  9. .setEndKeyClosed(ByteString.copyFromUtf8("j"))))
  10. .build());
  11. assertThat(subQueries.get(1).toProto(requestContext))
  12. .isEqualTo(
  13. ReadRowsRequest.newBuilder()

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void errorAfterRequestCompleteTest() {
  3. service.expectations.add(
  4. RpcExpectation.create()
  5. .expectRequest(Range.closedOpen("r1", "r3"))
  6. .expectRequest("r4")
  7. .respondWith("r2", "r4")
  8. .respondWithStatus(Code.UNAVAILABLE));
  9. // Second retry request is handled locally in ReadRowsRetryCompletedCallable
  10. List<String> actualResults = getResults(Query.create(TABLE_ID).range("r1", "r3").rowKey("r4"));
  11. Truth.assertThat(actualResults).containsExactly("r2", "r4");
  12. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void requestContextTest() {
  3. Query query = Query.create(TABLE_ID);
  4. ReadRowsRequest proto = query.toProto(requestContext);
  5. assertThat(proto).isEqualTo(expectedProtoBuilder().build());
  6. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void rowKeysTest() {
  3. Query query =
  4. Query.create(TABLE_ID)
  5. .rowKey("simple-string")
  6. .rowKey(ByteString.copyFromUtf8("byte-string"));
  7. ReadRowsRequest.Builder expectedProto = expectedProtoBuilder();
  8. expectedProto
  9. .getRowsBuilder()
  10. .addRowKeys(ByteString.copyFromUtf8("simple-string"))
  11. .addRowKeys(ByteString.copyFromUtf8("byte-string"));
  12. ReadRowsRequest actualProto = query.toProto(requestContext);
  13. assertThat(actualProto).isEqualTo(expectedProto.build());
  14. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void errorAfterRowLimitMetTest() {
  3. service.expectations.add(
  4. RpcExpectation.create()
  5. .expectRequest(Range.closedOpen("r1", "r3"))
  6. .expectRowLimit(2)
  7. .respondWith("r1", "r2")
  8. .respondWithStatus(Code.UNAVAILABLE));
  9. // Second retry request is handled locally in ReadRowsRetryCompletedCallable
  10. List<String> actualResults = getResults(Query.create(TABLE_ID).range("r1", "r3").limit(2));
  11. Truth.assertThat(actualResults).containsExactly("r1", "r2");
  12. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void retryWithLastScannedKeyTest() {
  3. service.expectations.add(
  4. RpcExpectation.create()
  5. .expectRequest(Range.closedOpen("r1", "r9"))
  6. .respondWithLastScannedKey("r5")
  7. .respondWithStatus(Code.UNAVAILABLE));
  8. service.expectations.add(
  9. RpcExpectation.create().expectRequest(Range.open("r5", "r9")).respondWith("r7"));
  10. List<String> actualResults =
  11. getResults(Query.create(TABLE_ID).range(ByteStringRange.create("r1", "r9")));
  12. Truth.assertThat(actualResults).containsExactly("r7").inOrder();
  13. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void rowRangeTest() {
  3. Query query =
  4. Query.create(TABLE_ID)
  5. .range("simple-begin", "simple-end")
  6. .range(ByteString.copyFromUtf8("byte-begin"), ByteString.copyFromUtf8("byte-end"))
  7. .range(ByteStringRange.create("range-begin", "range-end"));
  8. Builder expectedProto = expectedProtoBuilder();
  9. expectedProto
  10. .getRowsBuilder()
  11. .addRowRanges(
  12. RowRange.newBuilder()
  13. .setStartKeyClosed(ByteString.copyFromUtf8("simple-begin"))
  14. .setEndKeyOpen(ByteString.copyFromUtf8("simple-end")))
  15. .addRowRanges(
  16. RowRange.newBuilder()
  17. .setStartKeyClosed(ByteString.copyFromUtf8("byte-begin"))
  18. .setEndKeyOpen(ByteString.copyFromUtf8("byte-end")))
  19. .addRowRanges(
  20. RowRange.newBuilder()
  21. .setStartKeyClosed(ByteString.copyFromUtf8("range-begin"))
  22. .setEndKeyOpen(ByteString.copyFromUtf8("range-end")));
  23. ReadRowsRequest actualProto = query.toProto(requestContext);
  24. assertThat(actualProto).isEqualTo(expectedProto.build());
  25. }

代码示例来源:origin: googleapis/google-cloud-java

  1. @Override
  2. public void call(Query request, ResponseObserver<RowT> responseObserver, ApiCallContext context) {
  3. ReadRowsRequest innerRequest = request.toProto(requestContext);
  4. inner.call(innerRequest, responseObserver, context);
  5. }

代码示例来源:origin: googleapis/google-cloud-java

  1. /** Demonstrates how to read an entire table. */
  2. public void readTable() {
  3. // [START scanning_all_rows]
  4. try {
  5. System.out.println("\nReading the entire table");
  6. Query query = Query.create(tableId);
  7. ServerStream<Row> rowStream = dataClient.readRows(query);
  8. for (Row r : rowStream) {
  9. System.out.println("Row Key: " + r.getKey().toStringUtf8());
  10. for (RowCell cell : r.getCells()) {
  11. System.out.printf(
  12. "Family: %s Qualifier: %s Value: %s%n",
  13. cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
  14. }
  15. }
  16. } catch (NotFoundException e) {
  17. System.err.println("Failed to read a non-existent table: " + e.getMessage());
  18. }
  19. // [END scanning_all_rows]
  20. }

代码示例来源:origin: googleapis/google-cloud-java

  1. private void deleteRows() throws InterruptedException, ExecutionException, TimeoutException {
  2. Query query = Query.create(tableId).prefix(rowPrefix);
  3. List<ApiFuture<Void>> futures = Lists.newArrayList();
  4. ServerStream<Row> rows = dataClient.readRows(query);
  5. for (Row row : rows) {
  6. ApiFuture<Void> future =
  7. dataClient.mutateRowAsync(RowMutation.create(tableId, row.getKey()).deleteRow());
  8. futures.add(future);
  9. }
  10. ApiFutures.allAsList(futures).get(10, TimeUnit.MINUTES);
  11. }

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

  1. /** {@inheritDoc} */
  2. @Override
  3. public void adapt(Get operation, ReadHooks readHooks, Query query) {
  4. Scan operationAsScan = new Scan(addKeyOnlyFilter(operation));
  5. scanAdapter.throwIfUnsupportedScan(operationAsScan);
  6. query.filter(scanAdapter.buildFilter(operationAsScan, readHooks))
  7. .rowKey(ByteString.copyFrom(operation.getRow()));
  8. }

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

  1. /** {@inheritDoc} */
  2. @Override
  3. public void adapt(Scan scan, ReadHooks readHooks, Query query) {
  4. throwIfUnsupportedScan(scan);
  5. toByteStringRange(scan, query);
  6. query.filter(buildFilter(scan, readHooks));
  7. if (LIMIT_AVAILABLE && scan.getLimit() > 0) {
  8. query.limit(scan.getLimit());
  9. }
  10. }

代码示例来源:origin: GoogleCloudPlatform/cloud-bigtable-client

  1. && guavaRange.lowerEndpoint().equals(guavaRange.upperEndpoint())) {
  2. query.rowKey(guavaRange.lowerEndpoint().getKey());
  3. } else {
  4. ByteStringRange byteRange = ByteStringRange.unbounded();
  5. query.range(byteRange);

代码示例来源:origin: googleapis/google-cloud-java

  1. @Test
  2. public void testFromProto() {
  3. ReadRowsRequest request =
  4. ReadRowsRequest.newBuilder()
  5. .setTableName(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
  6. .setAppProfileId(APP_PROFILE_ID)
  7. .setFilter(RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(".*")))
  8. .setRows(
  9. RowSet.newBuilder()
  10. .addRowKeys(ByteString.copyFromUtf8("row-key"))
  11. .addRowRanges(
  12. RowRange.newBuilder()
  13. .setStartKeyClosed(ByteString.copyFromUtf8("j"))
  14. .setEndKeyClosed(ByteString.copyFromUtf8("z"))))
  15. .build();
  16. Query query = Query.fromProto(request);
  17. assertThat(query.toProto(requestContext)).isEqualTo(request);
  18. }

相关文章