Search in sources :

Example 91 with Row

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

the class Filters method filterLimitCellsPerRowOffset.

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

Example 92 with Row

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

the class Filters method printRow.

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);
        }
        String labels = cell.getLabels().size() == 0 ? "" : " [" + String.join(",", cell.getLabels()) + "]";
        System.out.printf("\t%s: %s @%s%s%n", cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8(), cell.getTimestamp(), labels);
    }
    System.out.println();
}
Also used : RowCell(com.google.cloud.bigtable.data.v2.models.RowCell)

Example 93 with Row

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

the class Filters method readFilter.

// [END bigtable_filters_composing_condition]
// [END_EXCLUDE]
private static void readFilter(String projectId, String instanceId, String tableId, Filter filter) {
    // 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 : 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 94 with Row

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

the class HelloWorld method readSingleRow.

/**
 * Demonstrates how to read a single row from a table.
 */
public Row readSingleRow() {
    // [START bigtable_hw_get_by_key]
    try {
        System.out.println("\nReading a single row by row key");
        Row row = dataClient.readRow(tableId, ROW_KEY_PREFIX + 0);
        System.out.println("Row: " + row.getKey().toStringUtf8());
        for (RowCell cell : row.getCells()) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
        return row;
    } 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 95 with Row

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

the class Quickstart method quickstart.

public static void quickstart(String projectId, String instanceId, String tableId) {
    BigtableDataSettings settings = BigtableDataSettings.newBuilder().setProjectId(projectId).setInstanceId(instanceId).build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (BigtableDataClient dataClient = BigtableDataClient.create(settings)) {
        System.out.println("\nReading a single row by row key");
        Row row = dataClient.readRow(tableId, "r1");
        System.out.println("Row: " + row.getKey().toStringUtf8());
        for (RowCell cell : row.getCells()) {
            System.out.printf("Family: %s    Qualifier: %s    Value: %s%n", cell.getFamily(), cell.getQualifier().toStringUtf8(), cell.getValue().toStringUtf8());
        }
    } catch (NotFoundException e) {
        System.err.println("Failed to read from a non-existent table: " + e.getMessage());
    } catch (Exception e) {
        System.out.println("Error during quickstart: \n" + e.toString());
    }
}
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) BigtableDataClient(com.google.cloud.bigtable.data.v2.BigtableDataClient) BigtableDataSettings(com.google.cloud.bigtable.data.v2.BigtableDataSettings) NotFoundException(com.google.api.gax.rpc.NotFoundException)

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