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);
}
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();
}
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());
}
}
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]
}
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());
}
}
Aggregations