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

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

本文整理了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

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

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

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

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

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

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

/**
 * Adds a range to be looked up.
 *
 * @param start The beginning of the range (inclusive). Can be null to represent negative
 *     infinity.
 * @param end The end of the range (exclusive). Can be null to represent positive infinity.
 */
public Query range(String start, String end) {
 return range(wrapKey(start), wrapKey(end));
}

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

@Test
public void serializationTest() throws IOException, ClassNotFoundException {
 Query expected = Query.create(TABLE_ID).filter(FILTERS.key().regex(".*"));
 ByteArrayOutputStream bos = new ByteArrayOutputStream();
 ObjectOutputStream oos = new ObjectOutputStream(bos);
 oos.writeObject(expected);
 oos.close();
 ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
 Query actual = (Query) ois.readObject();
 assertThat(actual.toProto(requestContext)).isEqualTo(expected.toProto(requestContext));
}

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

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

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

@Test
public void shardTestKeyOffsets() {
 Query query = Query.create(TABLE_ID).range("a", "z");
     KeyOffset.create(ByteString.EMPTY, 100));
 List<Query> subQueries = query.shard(keyOffsets);
 assertThat(subQueries.get(0).toProto(requestContext))
   .isEqualTo(
     ReadRowsRequest.newBuilder()
               .setEndKeyClosed(ByteString.copyFromUtf8("j"))))
       .build());
 assertThat(subQueries.get(1).toProto(requestContext))
   .isEqualTo(
     ReadRowsRequest.newBuilder()

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

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

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

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

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

@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());
}

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

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

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

@Test
public void retryWithLastScannedKeyTest() {
 service.expectations.add(
   RpcExpectation.create()
     .expectRequest(Range.closedOpen("r1", "r9"))
     .respondWithLastScannedKey("r5")
     .respondWithStatus(Code.UNAVAILABLE));
 service.expectations.add(
   RpcExpectation.create().expectRequest(Range.open("r5", "r9")).respondWith("r7"));
 List<String> actualResults =
   getResults(Query.create(TABLE_ID).range(ByteStringRange.create("r1", "r9")));
 Truth.assertThat(actualResults).containsExactly("r7").inOrder();
}

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

@Test
public void rowRangeTest() {
 Query query =
   Query.create(TABLE_ID)
     .range("simple-begin", "simple-end")
     .range(ByteString.copyFromUtf8("byte-begin"), ByteString.copyFromUtf8("byte-end"))
     .range(ByteStringRange.create("range-begin", "range-end"));
 Builder expectedProto = expectedProtoBuilder();
 expectedProto
   .getRowsBuilder()
   .addRowRanges(
     RowRange.newBuilder()
       .setStartKeyClosed(ByteString.copyFromUtf8("simple-begin"))
       .setEndKeyOpen(ByteString.copyFromUtf8("simple-end")))
   .addRowRanges(
     RowRange.newBuilder()
       .setStartKeyClosed(ByteString.copyFromUtf8("byte-begin"))
       .setEndKeyOpen(ByteString.copyFromUtf8("byte-end")))
   .addRowRanges(
     RowRange.newBuilder()
       .setStartKeyClosed(ByteString.copyFromUtf8("range-begin"))
       .setEndKeyOpen(ByteString.copyFromUtf8("range-end")));
 ReadRowsRequest actualProto = query.toProto(requestContext);
 assertThat(actualProto).isEqualTo(expectedProto.build());
}

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

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

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

/** Demonstrates how to read an entire table. */
public void readTable() {
 // [START scanning_all_rows]
 try {
  System.out.println("\nReading the entire table");
  Query query = Query.create(tableId);
  ServerStream<Row> rowStream = dataClient.readRows(query);
  for (Row r : rowStream) {
   System.out.println("Row Key: " + r.getKey().toStringUtf8());
   for (RowCell cell : r.getCells()) {
    System.out.printf(
      "Family: %s    Qualifier: %s    Value: %s%n",
      cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
   }
  }
 } catch (NotFoundException e) {
  System.err.println("Failed to read a non-existent table: " + e.getMessage());
 }
 // [END scanning_all_rows]
}

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

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

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

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

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

/** {@inheritDoc} */
@Override
public void adapt(Scan scan, ReadHooks readHooks, Query query) {
 throwIfUnsupportedScan(scan);
 toByteStringRange(scan, query);
 query.filter(buildFilter(scan, readHooks));
 if (LIMIT_AVAILABLE && scan.getLimit() > 0) {
  query.limit(scan.getLimit());
 }
}

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

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

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

@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);
}

相关文章