use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project beam by apache.
the class BigQueryIOStorageReadTest method testFractionConsumedArrow.
@Test
public void testFractionConsumedArrow() throws Exception {
ReadSession readSession = ReadSession.newBuilder().setName("readSession").setArrowSchema(ArrowSchema.newBuilder().setSerializedSchema(serializeArrowSchema(ARROW_SCHEMA)).build()).setDataFormat(DataFormat.ARROW).build();
ReadRowsRequest expectedRequest = ReadRowsRequest.newBuilder().setReadStream("readStream").build();
List<String> names = Arrays.asList("A", "B", "C", "D", "E", "F", "G");
List<Long> values = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L);
List<ReadRowsResponse> responses = Lists.newArrayList(createResponseArrow(ARROW_SCHEMA, names.subList(0, 2), values.subList(0, 2), 0.0, 0.25), createResponseArrow(ARROW_SCHEMA, Lists.newArrayList(), Lists.newArrayList(), 0.25, 0.25), createResponseArrow(ARROW_SCHEMA, names.subList(2, 4), values.subList(2, 4), 0.3, 0.5), createResponseArrow(ARROW_SCHEMA, names.subList(4, 7), values.subList(4, 7), 0.7, 1.0));
StorageClient fakeStorageClient = mock(StorageClient.class);
when(fakeStorageClient.readRows(expectedRequest, "")).thenReturn(new FakeBigQueryServerStream<>(responses));
BigQueryStorageStreamSource<TableRow> streamSource = BigQueryStorageStreamSource.create(readSession, ReadStream.newBuilder().setName("readStream").build(), TABLE_SCHEMA, new TableRowParser(), TableRowJsonCoder.of(), new FakeBigQueryServices().withStorageClient(fakeStorageClient));
BoundedReader<TableRow> reader = streamSource.createReader(options);
// Before call to BoundedReader#start, fraction consumed must be zero.
assertEquals(0.0, reader.getFractionConsumed(), DELTA);
// Reads A.
assertTrue(reader.start());
assertEquals(0.125, reader.getFractionConsumed(), DELTA);
// Reads B.
assertTrue(reader.advance());
assertEquals(0.25, reader.getFractionConsumed(), DELTA);
// Reads C.
assertTrue(reader.advance());
assertEquals(0.4, reader.getFractionConsumed(), DELTA);
// Reads D.
assertTrue(reader.advance());
assertEquals(0.5, reader.getFractionConsumed(), DELTA);
// Reads E.
assertTrue(reader.advance());
assertEquals(0.8, reader.getFractionConsumed(), DELTA);
// Reads F.
assertTrue(reader.advance());
assertEquals(0.9, reader.getFractionConsumed(), DELTA);
// Reads G.
assertTrue(reader.advance());
assertEquals(1.0, reader.getFractionConsumed(), DELTA);
// Reaches the end.
assertFalse(reader.advance());
// We are done with the stream, so we should report 100% consumption.
assertEquals(Double.valueOf(1.0), reader.getFractionConsumed());
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project beam by apache.
the class BigQueryIOStorageReadTest method testReadFromStreamSource.
@Test
public void testReadFromStreamSource() throws Exception {
ReadSession readSession = ReadSession.newBuilder().setName("readSession").setAvroSchema(AvroSchema.newBuilder().setSchema(AVRO_SCHEMA_STRING)).build();
ReadRowsRequest expectedRequest = ReadRowsRequest.newBuilder().setReadStream("readStream").build();
List<GenericRecord> records = Lists.newArrayList(createRecord("A", 1, AVRO_SCHEMA), createRecord("B", 2, AVRO_SCHEMA), createRecord("C", 3, AVRO_SCHEMA));
List<ReadRowsResponse> responses = Lists.newArrayList(createResponse(AVRO_SCHEMA, records.subList(0, 2), 0.0, 0.50), createResponse(AVRO_SCHEMA, records.subList(2, 3), 0.5, 0.75));
StorageClient fakeStorageClient = mock(StorageClient.class);
when(fakeStorageClient.readRows(expectedRequest, "")).thenReturn(new FakeBigQueryServerStream<>(responses));
BigQueryStorageStreamSource<TableRow> streamSource = BigQueryStorageStreamSource.create(readSession, ReadStream.newBuilder().setName("readStream").build(), TABLE_SCHEMA, new TableRowParser(), TableRowJsonCoder.of(), new FakeBigQueryServices().withStorageClient(fakeStorageClient));
List<TableRow> rows = new ArrayList<>();
BoundedReader<TableRow> reader = streamSource.createReader(options);
for (boolean hasNext = reader.start(); hasNext; hasNext = reader.advance()) {
rows.add(reader.getCurrent());
}
System.out.println("Rows: " + rows);
assertEquals(3, rows.size());
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project beam by apache.
the class BigQueryServicesImplTest method testReadRowsSetsRequestCountMetric.
@Test
public void testReadRowsSetsRequestCountMetric() throws InterruptedException, IOException {
BigQueryServices.StorageClient client = mock(BigQueryServicesImpl.StorageClientImpl.class);
ReadRowsRequest request = null;
BigQueryServices.BigQueryServerStream<ReadRowsResponse> response = new BigQueryServices.BigQueryServerStream<ReadRowsResponse>() {
@Override
public Iterator<ReadRowsResponse> iterator() {
return null;
}
@Override
public void cancel() {
}
};
// Mock implementation.
when(client.readRows(request)).thenReturn(response);
// Real implementation.
when(client.readRows(any(), any())).thenCallRealMethod();
client.readRows(request, "myproject:mydataset.mytable");
verifyReadMetricWasSet("myproject", "mydataset", "mytable", "ok", 1);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCreateReadRowsCallable.
@Test
public void testCreateReadRowsCallable() throws InterruptedException {
ServerStreamingCallable<Query, Row> streamingCallable = enhancedBigtableStub.createReadRowsCallable(new DefaultRowAdapter());
Query request = Query.create("table-id").rowKey("row-key");
streamingCallable.call(request).iterator().next();
ReadRowsRequest expected = request.toProto(RequestContext.create(PROJECT_ID, INSTANCE_ID, APP_PROFILE_ID));
assertThat(fakeDataService.popLastRequest()).isEqualTo(expected);
}
use of com.google.bigtable.repackaged.com.google.bigtable.v2.ReadRowsRequest in project java-bigtable by googleapis.
the class EnhancedBigtableStubTest method testCreateReadRowsRawCallable.
@Test
public void testCreateReadRowsRawCallable() throws InterruptedException {
ServerStreamingCallable<ReadRowsRequest, Row> callable = enhancedBigtableStub.createReadRowsRawCallable(new DefaultRowAdapter());
ReadRowsRequest expectedRequest = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-1").setRows(RowSet.newBuilder().addRowKeys(ByteString.copyFromUtf8("test-row-key"))).build();
callable.call(expectedRequest).iterator().next();
assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest);
ReadRowsRequest expectedRequest2 = ReadRowsRequest.newBuilder().setTableName(TABLE_NAME).setAppProfileId("app-profile-2").build();
callable.call(expectedRequest2).iterator().next();
assertThat(fakeDataService.popLastRequest()).isEqualTo(expectedRequest2);
}
Aggregations