Search in sources :

Example 21 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class TestBigtableVeneerApi method testGetDataClient.

@Test
public void testGetDataClient() throws Exception {
    assertTrue(bigtableApi.getDataClient() instanceof DataClientVeneerApi);
    Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
    bigtableApi.getDataClient().readRowsAsync(query);
    ReadRowsRequest request = fakeDataService.popLastRequest();
    assertEquals(ROW_KEY, request.getRows().getRowKeys(0).toStringUtf8());
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 22 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class TestGetAdapter method testAdKeyOnlyFilterWithFilter.

@Test
public void testAdKeyOnlyFilterWithFilter() throws IOException {
    Get get = makeValidGet(dataHelper.randomData(PREFIX_DATA));
    get.setCheckExistenceOnly(true);
    get.setFilter(new KeyOnlyFilter());
    getAdapter.adapt(get, throwingReadHooks, query);
    Filters.Filter filterOne = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
    Filters.Filter filterTwo = FILTERS.chain().filter(FILTERS.limit().cellsPerColumn(1)).filter(FILTERS.value().strip());
    Assert.assertEquals(FILTERS.chain().filter(filterOne).filter(filterTwo).toProto(), query.toProto(requestContext).getFilter());
}
Also used : KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) Filters(com.google.cloud.bigtable.data.v2.models.Filters) Get(org.apache.hadoop.hbase.client.Get) Test(org.junit.Test)

Example 23 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class BigtableAsyncTable method scan.

/**
 * {@inheritDoc}
 */
public void scan(Scan scan, final ScanResultConsumer consumer) {
    if (AbstractBigtableTable.hasWhileMatchFilter(scan.getFilter())) {
        throw new UnsupportedOperationException("scan with consumer and while match filter is not allowed");
    }
    Query query = hbaseAdapter.adapt(scan);
    clientWrapper.readRowsAsync(query, new StreamObserver<Result>() {

        @Override
        public void onNext(Result value) {
            consumer.onNext(value);
        }

        @Override
        public void onError(Throwable t) {
            consumer.onError(t);
        }

        @Override
        public void onCompleted() {
            consumer.onComplete();
        }
    });
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Result(org.apache.hadoop.hbase.client.Result)

Example 24 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable-hbase by googleapis.

the class TestDataClientVeneerApi method testReadRows.

@Test
public void testReadRows() throws IOException {
    Query query = Query.create(TABLE_ID).rowKey(ROW_KEY);
    when(mockDataClient.readRowsCallable(Mockito.<RowResultAdapter>any())).thenReturn(mockStreamingCallable).thenReturn(mockStreamingCallable);
    when(serverStream.iterator()).thenReturn(ImmutableList.of(Result.EMPTY_RESULT, EXPECTED_RESULT, EXPECTED_RESULT).iterator()).thenReturn(ImmutableList.<Result>of().iterator());
    when(mockStreamingCallable.call(Mockito.eq(query), Mockito.any(GrpcCallContext.class))).thenReturn(serverStream).thenReturn(serverStream);
    ResultScanner resultScanner = dataClientWrapper.readRows(query);
    assertResult(Result.EMPTY_RESULT, resultScanner.next());
    assertResult(EXPECTED_RESULT, resultScanner.next());
    doNothing().when(serverStream).cancel();
    resultScanner.close();
    ResultScanner noRowsResultScanner = dataClientWrapper.readRows(query);
    assertNull(noRowsResultScanner.next());
    verify(serverStream).cancel();
    verify(mockDataClient, times(2)).readRowsCallable(Mockito.<RowResultAdapter>any());
    verify(serverStream, times(2)).iterator();
    verify(mockStreamingCallable, times(2)).call(Mockito.eq(query), Mockito.any(GrpcCallContext.class));
}
Also used : ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) GrpcCallContext(com.google.api.gax.grpc.GrpcCallContext) Query(com.google.cloud.bigtable.data.v2.models.Query) Result(org.apache.hadoop.hbase.client.Result) Test(org.junit.Test)

Example 25 with Query

use of com.google.cloud.bigtable.data.v2.models.Query in project java-bigtable by googleapis.

the class ReadRowsUserCallableTest method testFirstIsLimited.

@Test
public void testFirstIsLimited() {
    ServerStreamingStashCallable<ReadRowsRequest, Row> innerCallable = new ServerStreamingStashCallable<>();
    ReadRowsUserCallable<Row> callable = new ReadRowsUserCallable<>(innerCallable, REQUEST_CONTEXT);
    Query query = Query.create("fake-table");
    callable.first().call(query);
    Truth.assertThat(innerCallable.getActualRequest()).isEqualTo(query.limit(1).toProto(REQUEST_CONTEXT));
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ServerStreamingStashCallable(com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.cloud.bigtable.data.v2.models.Row) Test(org.junit.Test)

Aggregations

Query (com.google.cloud.bigtable.data.v2.models.Query)34 Row (com.google.cloud.bigtable.data.v2.models.Row)24 Test (org.junit.Test)20 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)7 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)7 IOException (java.io.IOException)7 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)5 ByteString (com.google.protobuf.ByteString)5 Result (org.apache.hadoop.hbase.client.Result)5 GrpcCallContext (com.google.api.gax.grpc.GrpcCallContext)4 Filters (com.google.cloud.bigtable.data.v2.models.Filters)4 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)4 DefaultReadHooks (com.google.cloud.bigtable.hbase.adapters.read.DefaultReadHooks)3 ReadHooks (com.google.cloud.bigtable.hbase.adapters.read.ReadHooks)3 SpanName (com.google.api.gax.tracing.SpanName)2 BulkMutation (com.google.cloud.bigtable.data.v2.models.BulkMutation)2 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)2 ReadRowsUserCallable (com.google.cloud.bigtable.data.v2.stub.readrows.ReadRowsUserCallable)2 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)2 Scan (org.apache.hadoop.hbase.client.Scan)2