Search in sources :

Example 51 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.

the class ReadRowsUserCallable method call.

@Override
public void call(Query request, ResponseObserver<RowT> responseObserver, ApiCallContext context) {
    ReadRowsRequest innerRequest = request.toProto(requestContext);
    inner.call(innerRequest, responseObserver, context);
}
Also used : ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest)

Example 52 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable-hbase by googleapis.

the class CloudBigtableScanConfigurationTest method testRegularAndRuntimeParametersAreEqualWithRequest.

/**
 * This ensures that the config built from regular parameters with a request are the same as the
 * config built from runtime parameters, so that we don't have to use runtime parameters to repeat
 * the same tests.
 */
@Test
public void testRegularAndRuntimeParametersAreEqualWithRequest() {
    ReadRowsRequest request = ReadRowsRequest.newBuilder().setRowsLimit(10).build();
    CloudBigtableScanConfiguration withRegularParameters = config.toBuilder().withRequest(request).withKeys(START_ROW, STOP_ROW).withConfiguration("somekey", "somevalue").build();
    CloudBigtableScanConfiguration withRuntimeParameters = new CloudBigtableScanConfiguration.Builder().withTableId(StaticValueProvider.of(TABLE)).withProjectId(StaticValueProvider.of(PROJECT)).withInstanceId(StaticValueProvider.of(INSTANCE)).withRequest(StaticValueProvider.of(request)).withKeys(START_ROW, STOP_ROW).withConfiguration("somekey", StaticValueProvider.of("somevalue")).build();
    Assert.assertEquals(withRegularParameters, withRuntimeParameters);
    // Verify with requests.
    ReadRowsRequest updatedRequest = withRegularParameters.getRequest();
    withRegularParameters = withRegularParameters.toBuilder().withRequest(updatedRequest).build();
    withRuntimeParameters = withRuntimeParameters.toBuilder().withRequest(StaticValueProvider.of(updatedRequest)).build();
    Assert.assertEquals(withRegularParameters, withRuntimeParameters);
}
Also used : ReadRowsRequest(com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 53 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable-hbase by googleapis.

the class CloudBigtableScanConfigurationTest method testRegularAndRuntimeParametersAreEqualWithScan.

/**
 * This ensures that the config built from regular parameters with a scan are the same as the
 * config built from runtime parameters, so that we don't have to use runtime parameters to repeat
 * the same tests.
 */
@Test
public void testRegularAndRuntimeParametersAreEqualWithScan() {
    CloudBigtableScanConfiguration withRegularParameters = config.toBuilder().withConfiguration("somekey", "somevalue").build();
    CloudBigtableScanConfiguration withRuntimeParameters = new CloudBigtableScanConfiguration.Builder().withTableId(StaticValueProvider.of(TABLE)).withProjectId(StaticValueProvider.of(PROJECT)).withInstanceId(StaticValueProvider.of(INSTANCE)).withScan(new Scan(START_ROW, STOP_ROW)).withConfiguration("somekey", StaticValueProvider.of("somevalue")).build();
    Assert.assertEquals(withRegularParameters, withRuntimeParameters);
    // Verify with requests.
    ReadRowsRequest request = withRegularParameters.getRequest();
    withRegularParameters = withRegularParameters.toBuilder().withRequest(request).build();
    withRuntimeParameters = withRuntimeParameters.toBuilder().withRequest(StaticValueProvider.of(request)).build();
    Assert.assertEquals(withRegularParameters, withRuntimeParameters);
}
Also used : Scan(org.apache.hadoop.hbase.client.Scan) ReadRowsRequest(com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 54 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable-hbase by googleapis.

the class CloudBigtableScanConfigurationTest method testQuery.

@Test
public void testQuery() {
    Filters.Filter filter = Filters.FILTERS.family().exactMatch("someFamily");
    ReadRowsRequest request = config.toBuilder().withQuery(Query.create("SomeTable").filter(filter)).build().getRequest();
    Assert.assertEquals(request.getTableName(), config.getRequest().getTableName());
    Assert.assertEquals(request.getFilter(), filter.toProto());
}
Also used : Filters(com.google.bigtable.repackaged.com.google.cloud.bigtable.data.v2.models.Filters) ReadRowsRequest(com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest) Test(org.junit.Test)

Example 55 with ReadRowsRequest

use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project beam by apache.

the class BigQueryIOStorageQueryTest method doReadFromBigQueryIO.

private void doReadFromBigQueryIO(boolean templateCompatibility) throws Exception {
    TableReference sourceTableRef = BigQueryHelpers.parseTableSpec("project:dataset.table");
    fakeDatasetService.createDataset(sourceTableRef.getProjectId(), sourceTableRef.getDatasetId(), "asia-northeast1", "Fake plastic tree^H^H^H^Htables", null);
    fakeDatasetService.createTable(new Table().setTableReference(sourceTableRef).setLocation("asia-northeast1"));
    Table queryResultTable = new Table().setSchema(TABLE_SCHEMA).setNumBytes(0L);
    String encodedQuery = FakeBigQueryServices.encodeQueryResult(queryResultTable);
    fakeJobService.expectDryRunQuery(options.getProject(), encodedQuery, new JobStatistics().setQuery(new JobStatistics2().setTotalBytesProcessed(1024L * 1024L).setReferencedTables(ImmutableList.of(sourceTableRef))));
    ReadSession readSession = ReadSession.newBuilder().setName("readSessionName").setAvroSchema(AvroSchema.newBuilder().setSchema(AVRO_SCHEMA_STRING)).addStreams(ReadStream.newBuilder().setName("streamName")).setDataFormat(DataFormat.AVRO).build();
    ReadRowsRequest expectedReadRowsRequest = ReadRowsRequest.newBuilder().setReadStream("streamName").build();
    List<GenericRecord> records = Lists.newArrayList(createRecord("A", 1, AVRO_SCHEMA), createRecord("B", 2, AVRO_SCHEMA), createRecord("C", 3, AVRO_SCHEMA), createRecord("D", 4, AVRO_SCHEMA));
    List<ReadRowsResponse> readRowsResponses = Lists.newArrayList(createResponse(AVRO_SCHEMA, records.subList(0, 2), 0.0, 0.500), createResponse(AVRO_SCHEMA, records.subList(2, 4), 0.5, 0.875));
    // 
    // Note that since the temporary table name is generated by the pipeline, we can't match the
    // expected create read session request exactly. For now, match against any appropriately typed
    // proto object.
    // 
    StorageClient fakeStorageClient = mock(StorageClient.class, withSettings().serializable());
    when(fakeStorageClient.createReadSession(any())).thenReturn(readSession);
    when(fakeStorageClient.readRows(expectedReadRowsRequest, "")).thenReturn(new FakeBigQueryServerStream<>(readRowsResponses));
    BigQueryIO.TypedRead<KV<String, Long>> typedRead = BigQueryIO.read(new ParseKeyValue()).fromQuery(encodedQuery).withMethod(Method.DIRECT_READ).withTestServices(new FakeBigQueryServices().withDatasetService(fakeDatasetService).withJobService(fakeJobService).withStorageClient(fakeStorageClient));
    if (templateCompatibility) {
        typedRead = typedRead.withTemplateCompatibility();
    }
    PCollection<KV<String, Long>> output = p.apply(typedRead);
    PAssert.that(output).containsInAnyOrder(ImmutableList.of(KV.of("A", 1L), KV.of("B", 2L), KV.of("C", 3L), KV.of("D", 4L)));
    p.run();
}
Also used : JobStatistics(com.google.api.services.bigquery.model.JobStatistics) JobStatistics2(com.google.api.services.bigquery.model.JobStatistics2) Table(com.google.api.services.bigquery.model.Table) ReadSession(com.google.cloud.bigquery.storage.v1.ReadSession) ReadRowsRequest(com.google.cloud.bigquery.storage.v1.ReadRowsRequest) StorageClient(org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient) ByteString(com.google.protobuf.ByteString) KV(org.apache.beam.sdk.values.KV) TableReference(com.google.api.services.bigquery.model.TableReference) BigQueryResourceNaming.createTempTableReference(org.apache.beam.sdk.io.gcp.bigquery.BigQueryResourceNaming.createTempTableReference) ReadRowsResponse(com.google.cloud.bigquery.storage.v1.ReadRowsResponse) FakeBigQueryServices(org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices) GenericRecord(org.apache.avro.generic.GenericRecord)

Aggregations

Test (org.junit.Test)59 ReadRowsRequest (com.google.cloud.bigquery.storage.v1.ReadRowsRequest)31 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)28 ReadRowsResponse (com.google.cloud.bigquery.storage.v1.ReadRowsResponse)24 ReadSession (com.google.cloud.bigquery.storage.v1.ReadSession)17 ReadRowsRequest (com.google.cloud.bigquery.storage.v1beta2.ReadRowsRequest)16 ReadRowsResponse (com.google.cloud.bigquery.storage.v1beta2.ReadRowsResponse)10 StorageClient (org.apache.beam.sdk.io.gcp.bigquery.BigQueryServices.StorageClient)10 FakeBigQueryServices (org.apache.beam.sdk.io.gcp.testing.FakeBigQueryServices)10 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)9 Row (com.google.cloud.bigtable.data.v2.models.Row)9 CreateReadSessionRequest (com.google.cloud.bigquery.storage.v1.CreateReadSessionRequest)8 TableRow (com.google.api.services.bigquery.model.TableRow)7 Query (com.google.cloud.bigtable.data.v2.models.Query)7 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 ByteString (com.google.protobuf.ByteString)7 GenericRecord (org.apache.avro.generic.GenericRecord)6 TableRowParser (org.apache.beam.sdk.io.gcp.bigquery.BigQueryIO.TableRowParser)6 ReadSession (com.google.cloud.bigquery.storage.v1beta2.ReadSession)5 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)5