Search in sources :

Example 6 with Row

use of com.google.bigtable.v1.Row in project beam by apache.

the class BigtableIOTest method testReading.

/** Tests reading all rows from a table. */
@Test
public void testReading() throws Exception {
    final String table = "TEST-MANY-ROWS-TABLE";
    final int numRows = 1001;
    List<Row> testRows = makeTableData(table, numRows);
    service.setupSampleRowKeys(table, 3, 1000L);
    runReadTest(defaultRead.withTableId(table), testRows);
    logged.verifyInfo(String.format("Closing reader after reading %d records.", numRows / 3));
}
Also used : ByteString(com.google.protobuf.ByteString) Row(com.google.bigtable.v2.Row) Test(org.junit.Test)

Example 7 with Row

use of com.google.bigtable.v1.Row in project beam by apache.

the class BigtableWriteIT method getTableData.

/** Helper function to get a table's data. */
private List<KV<ByteString, ByteString>> getTableData(String tableName) throws IOException {
    // Add empty range to avoid TARGET_NOT_SET error
    RowRange range = RowRange.newBuilder().setStartKeyClosed(ByteString.EMPTY).setEndKeyOpen(ByteString.EMPTY).build();
    RowSet rowSet = RowSet.newBuilder().addRowRanges(range).build();
    ReadRowsRequest.Builder readRowsRequestBuilder = ReadRowsRequest.newBuilder().setTableName(tableName).setRows(rowSet);
    ResultScanner<Row> scanner = session.getDataClient().readRows(readRowsRequestBuilder.build());
    Row currentRow;
    List<KV<ByteString, ByteString>> tableData = new ArrayList<>();
    while ((currentRow = scanner.next()) != null) {
        ByteString key = currentRow.getKey();
        ByteString value = currentRow.getFamilies(0).getColumns(0).getCells(0).getValue();
        tableData.add(KV.of(key, value));
    }
    scanner.close();
    return tableData;
}
Also used : RowRange(com.google.bigtable.v2.RowRange) ByteString(com.google.protobuf.ByteString) RowSet(com.google.bigtable.v2.RowSet) ArrayList(java.util.ArrayList) ReadRowsRequest(com.google.bigtable.v2.ReadRowsRequest) Row(com.google.bigtable.v2.Row) KV(org.apache.beam.sdk.values.KV)

Example 8 with Row

use of com.google.bigtable.v1.Row in project beam by apache.

the class BigtableIOTest method makeTableData.

/** Helper function to create a table and return the rows that it created. */
private static List<Row> makeTableData(String tableId, int numRows) {
    service.createTable(tableId);
    Map<ByteString, ByteString> testData = service.getTable(tableId);
    List<Row> testRows = new ArrayList<>(numRows);
    for (int i = 0; i < numRows; ++i) {
        ByteString key = ByteString.copyFromUtf8(String.format("key%09d", i));
        ByteString value = ByteString.copyFromUtf8(String.format("value%09d", i));
        testData.put(key, value);
        testRows.add(makeRow(key, value));
    }
    return testRows;
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Row(com.google.bigtable.v2.Row)

Example 9 with Row

use of com.google.bigtable.v1.Row in project beam by apache.

the class BigtableIOTest method testReadingWithFilter.

/** Tests reading all rows using a filter. */
@Test
public void testReadingWithFilter() throws Exception {
    final String table = "TEST-FILTER-TABLE";
    final int numRows = 1001;
    List<Row> testRows = makeTableData(table, numRows);
    String regex = ".*17.*";
    final KeyMatchesRegex keyPredicate = new KeyMatchesRegex(regex);
    Iterable<Row> filteredRows = Iterables.filter(testRows, new Predicate<Row>() {

        @Override
        public boolean apply(@Nullable Row input) {
            verifyNotNull(input, "input");
            return keyPredicate.apply(input.getKey());
        }
    });
    RowFilter filter = RowFilter.newBuilder().setRowKeyRegexFilter(ByteString.copyFromUtf8(regex)).build();
    service.setupSampleRowKeys(table, 5, 10L);
    runReadTest(defaultRead.withTableId(table).withRowFilter(filter), Lists.newArrayList(filteredRows));
}
Also used : RowFilter(com.google.bigtable.v2.RowFilter) ByteString(com.google.protobuf.ByteString) Row(com.google.bigtable.v2.Row) Test(org.junit.Test)

Aggregations

Row (com.google.bigtable.v2.Row)7 ByteString (com.google.protobuf.ByteString)7 Test (org.junit.Test)5 ByteString (com.google.bigtable.repackaged.com.google.protobuf.ByteString)2 Column (com.google.bigtable.v1.Column)2 Family (com.google.bigtable.v1.Family)2 DeleteFromRow (com.google.bigtable.v1.Mutation.DeleteFromRow)2 ReadRowsRequest (com.google.bigtable.v1.ReadRowsRequest)2 Row (com.google.bigtable.v1.Row)2 RowFilter (com.google.bigtable.v1.RowFilter)2 Builder (com.google.bigtable.v1.RowFilter.Chain.Builder)2 ByteArrayByteIterator (com.yahoo.ycsb.ByteArrayByteIterator)2 ArrayList (java.util.ArrayList)2 ExecutionException (java.util.concurrent.ExecutionException)2 RowRange (com.google.bigtable.v1.RowRange)1 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)1 RowFilter (com.google.bigtable.v2.RowFilter)1 RowRange (com.google.bigtable.v2.RowRange)1 RowSet (com.google.bigtable.v2.RowSet)1 ByteIterator (com.yahoo.ycsb.ByteIterator)1