Search in sources :

Example 36 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class Filters method filterLimitCellsPerRow.

public static void filterLimitCellsPerRow(String projectId, String instanceId, String tableId) {
    // A filter that matches the first 2 cells of each row
    Filter filter = FILTERS.limit().cellsPerRow(2);
    readFilter(projectId, instanceId, tableId, filter);
}
Also used : Filter(com.google.cloud.bigtable.data.v2.models.Filters.Filter)

Example 37 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class HelloWorld method readSpecificCells.

/**
 * Demonstrates how to access specific cells by family and qualifier.
 */
public List<RowCell> readSpecificCells() {
    // [START bigtable_hw_get_by_key]
    try {
        System.out.println("\nReading specific cells by family and qualifier");
        Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
        System.out.println("Row: " + row.getKey().toStringUtf8());
        List<RowCell> cells = row.getCells(COLUMN_FAMILY, COLUMN_QUALIFIER_NAME);
        for (RowCell cell : cells) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
        return cells;
    } catch (NotFoundException e) {
        System.err.println("Failed to read from a non-existent table: " + e.getMessage());
        return null;
    }
// [END bigtable_hw_get_by_key]
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) NotFoundException(com.google.api.gax.rpc.NotFoundException) Row(com.google.cloud.bigtable.data.v2.models.Row)

Example 38 with Row

use of com.google.cloud.bigtable.data.v2.models.Row 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]
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) ArrayList(java.util.ArrayList) RowCell(com.google.cloud.bigtable.data.v2.models.RowCell) NotFoundException(com.google.api.gax.rpc.NotFoundException) Row(com.google.cloud.bigtable.data.v2.models.Row)

Example 39 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class Reads method readRowRanges.

public static void readRowRanges(String projectId, String instanceId, String tableId) {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        Query query = Query.create(tableId).range("phone#4c410523#20190501", "phone#4c410523#20190601").range("phone#5c10102#20190501", "phone#5c10102#20190601");
        ServerStream<Row> rows = dataClient.readRows(query);
        for (Row row : rows) {
            printRow(row);
        }
    } catch (IOException e) {
        System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
    }
}
Also used : Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Example 40 with Row

use of com.google.cloud.bigtable.data.v2.models.Row in project java-bigtable by googleapis.

the class Reads method readFilter.

public static void readFilter(String projectId, String instanceId, String tableId) {
    Filters.Filter filter = FILTERS.value().regex("PQ2A.*");
    // the "close" method on the client to safely clean up any remaining background resources.
    try (BigtableDataClient dataClient = BigtableDataClient.create(projectId, instanceId)) {
        Query query = Query.create(tableId).filter(filter);
        ServerStream<Row> rows = dataClient.readRows(query);
        for (Row row : rows) {
            printRow(row);
        }
    } catch (IOException e) {
        System.out.println("Unable to initialize service client, as a network error occurred: \n" + e.toString());
    }
}
Also used : Filters(com.google.cloud.bigtable.data.v2.models.Filters) Query(com.google.cloud.bigtable.data.v2.models.Query) Row(com.google.cloud.bigtable.data.v2.models.Row) IOException(java.io.IOException) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient)

Aggregations

Row (com.google.cloud.bigtable.data.v2.models.Row)71 Test (org.junit.Test)64 Query (com.google.cloud.bigtable.data.v2.models.Query)34 ByteString (com.google.protobuf.ByteString)28 ReadModifyWriteRow (com.google.cloud.bigtable.data.v2.models.ReadModifyWriteRow)26 BigtableDataClient (com.google.cloud.bigtable.data.v2.BigtableDataClient)19 RowCell (com.google.cloud.bigtable.data.v2.models.RowCell)19 ReadRowsRequest (com.google.bigtable.v2.ReadRowsRequest)13 Filter (com.google.cloud.bigtable.data.v2.models.Filters.Filter)11 IOException (java.io.IOException)10 RowMutation (com.google.cloud.bigtable.data.v2.models.RowMutation)9 ServerStreamingStashCallable (com.google.cloud.bigtable.gaxx.testing.FakeStreamingApi.ServerStreamingStashCallable)7 Put (org.apache.hadoop.hbase.client.Put)7 DefaultRowAdapter (com.google.cloud.bigtable.data.v2.models.DefaultRowAdapter)6 MutateRowRequest (com.google.bigtable.v2.MutateRowRequest)5 Mutation (com.google.bigtable.v2.Mutation)5 SetCell (com.google.bigtable.v2.Mutation.SetCell)5 NotFoundException (com.google.api.gax.rpc.NotFoundException)4 ReadRowsResponse (com.google.bigtable.v2.ReadRowsResponse)4 ConditionalRowMutation (com.google.cloud.bigtable.data.v2.models.ConditionalRowMutation)4