use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class HelloWorld method readTable.
/**
* Demonstrates how to read an entire table.
*/
public List<Row> readTable() {
// [START bigtable_hw_scan_all]
try {
System.out.println("\nReading the entire table");
Query query = Query.create(tableId);
ServerStream<Row> rowStream = dataClient.readRows(query);
List<Row> tableRows = new ArrayList<>();
for (Row r : rowStream) {
System.out.println("Row Key: " + r.getKey().toStringUtf8());
tableRows.add(r);
for (RowCell cell : r.getCells()) {
System.out.printf("Family: %s Qualifier: %s Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
}
}
return tableRows;
} catch (NotFoundException e) {
System.err.println("Failed to read a non-existent table: " + e.getMessage());
return null;
}
// [END bigtable_hw_scan_all]
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class Reads method printRow.
// [END bigtable_reads_filter]
// [END_EXCLUDE]
private static void printRow(Row row) {
System.out.printf("Reading data for %s%n", row.getKey().toStringUtf8());
String colFamily = "";
for (RowCell cell : row.getCells()) {
if (!cell.getFamily().equals(colFamily)) {
colFamily = cell.getFamily();
System.out.printf("Column Family %s%n", colFamily);
}
System.out.printf("\t%s: %s @%s%n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp());
}
System.out.println();
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable by googleapis.
the class BigtableDataClientTest method proxyNewBulkReadRowsTest.
@Test
public void proxyNewBulkReadRowsTest() {
Mockito.when(mockStub.newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any())).thenReturn(mockBulkReadRowsBatcher);
ApiFuture<Row> expectedResponse = ApiFutures.immediateFuture(Row.create(ByteString.copyFromUtf8("fake-row-key"), Collections.<RowCell>emptyList()));
ByteString request = ByteString.copyFromUtf8("fake-row-key");
Batcher<ByteString, Row> batcher = bigtableDataClient.newBulkReadRowsBatcher("fake-table");
Mockito.when(mockBulkReadRowsBatcher.add(request)).thenReturn(expectedResponse);
ApiFuture<Row> actualResponse = batcher.add(request);
assertThat(actualResponse).isSameInstanceAs(expectedResponse);
Mockito.verify(mockStub).newBulkReadRowsBatcher(Mockito.any(Query.class), Mockito.any());
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable-hbase by googleapis.
the class TestBigtableTable method getScanner_withBigtableResultScannerAdapter.
@Test
public void getScanner_withBigtableResultScannerAdapter() throws IOException {
when(mockBigtableDataClient.readRows(isA(Query.class))).thenReturn(mockResultScanner);
// A row with no matching label. In case of {@link BigtableResultScannerAdapter} the result is
// non-null.
Result expected = Result.create(ImmutableList.<Cell>of(new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, ByteString.EMPTY.toByteArray(), Collections.singletonList("label-in")), new RowCell(Bytes.toBytes("row_key"), Bytes.toBytes("family_name"), Bytes.toBytes("q_name"), 0, Bytes.toBytes("value"))));
when(mockResultScanner.next()).thenReturn(expected);
QualifierFilter filter = new QualifierFilter(CompareOp.EQUAL, new BinaryComparator(Bytes.toBytes("x")));
Scan scan = new Scan();
scan.setFilter(filter);
org.apache.hadoop.hbase.client.ResultScanner resultScanner = table.getScanner(scan);
Result result = resultScanner.next();
assertEquals("row_key", new String(result.getRow()));
List<org.apache.hadoop.hbase.Cell> cells = result.getColumnCells("family_name".getBytes(), "q_name".getBytes());
// HBase ResultScanner now allows cells with labels
assertEquals(2, cells.size());
assertEquals("", new String(CellUtil.cloneValue(cells.get(0))));
assertEquals("value", new String(CellUtil.cloneValue(cells.get(1))));
verify(mockBigtableDataClient).readRows(isA(Query.class));
verify(mockResultScanner).next();
}
use of com.google.cloud.bigtable.data.v2.models.RowCell in project java-bigtable-hbase by googleapis.
the class TestBatchExecutor method testPartialResults.
@Test
public void testPartialResults() throws Exception {
when(mockBigtableApi.getDataClient()).thenReturn(mockDataClientWrapper);
when(mockDataClientWrapper.createBulkRead(isA(String.class))).thenReturn(mockBulkRead);
byte[] key1 = randomBytes(8);
byte[] key2 = randomBytes(8);
Result expected = Result.create(ImmutableList.<org.apache.hadoop.hbase.Cell>of(new RowCell(key1, Bytes.toBytes("cf"), Bytes.toBytes(""), 10, Bytes.toBytes("hi!"), ImmutableList.<String>of())));
RuntimeException exception = new RuntimeException("Something bad happened");
when(mockBulkRead.add(any(ByteString.class), any(Filters.Filter.class))).thenReturn(ApiFutures.immediateFuture(expected)).thenReturn(ApiFutures.<Result>immediateFailedFuture(exception));
List<Get> gets = Arrays.asList(new Get(key1), new Get(key2));
Object[] results = new Object[2];
try {
createExecutor().batch(gets, results);
} catch (RetriesExhaustedWithDetailsException ignored) {
}
assertTrue("first result is a result", results[0] instanceof Result);
assertTrue(matchesRow(expected).matches(results[0]));
Assert.assertEquals(exception, results[1]);
}
Aggregations