Search in sources :

Example 11 with Row

use of com.google.bigtable.v2.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 12 with Row

use of com.google.bigtable.v2.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

ByteString (com.google.protobuf.ByteString)10 Row (com.google.bigtable.v2.Row)7 Test (org.junit.Test)7 RowFilter (com.google.bigtable.v2.RowFilter)3 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 BigtableSource (org.apache.beam.sdk.io.gcp.bigtable.BigtableIO.BigtableSource)2 RowRange (com.google.bigtable.v1.RowRange)1 Mutation (com.google.bigtable.v2.Mutation)1 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)1 RowRange (com.google.bigtable.v2.RowRange)1