2727import com .google .cloud .bigtable .data .v2 .models .Row ;
2828import com .google .cloud .bigtable .data .v2 .models .RowCell ;
2929import java .io .IOException ;
30+ import java .nio .charset .StandardCharsets ;
3031import java .time .Instant ;
3132import java .time .temporal .ChronoUnit ;
33+ import java .util .Base64 ;
3234
3335public class Filters {
3436
@@ -46,6 +48,7 @@ public static void filterLimitRowSample() {
4648 public static void filterLimitRowSample (String projectId , String instanceId , String tableId ) {
4749 // A filter that matches cells from a row with probability .75
4850 Filter filter = FILTERS .key ().sample (.75 );
51+ readRowFilter (projectId , instanceId , tableId , filter );
4952 readFilter (projectId , instanceId , tableId , filter );
5053 }
5154 // [END bigtable_filters_limit_row_sample]
@@ -67,6 +70,7 @@ public static void filterLimitRowRegex(String projectId, String instanceId, Stri
6770 // [END bigtable_filters_limit_row_regex]
6871
6972 // [START bigtable_filters_limit_cells_per_col]
73+ // [START bigtable_hw_create_filter]
7074 public static void filterLimitCellsPerCol () {
7175 // TODO(developer): Replace these variables before running the sample.
7276 String projectId = "my-project-id" ;
@@ -80,6 +84,7 @@ public static void filterLimitCellsPerCol(String projectId, String instanceId, S
8084 Filter filter = FILTERS .limit ().cellsPerColumn (2 );
8185 readFilter (projectId , instanceId , tableId , filter );
8286 }
87+ // [END bigtable_hw_create_filter]
8388 // [END bigtable_filters_limit_cells_per_col]
8489
8590 // [START bigtable_filters_limit_cells_per_row]
@@ -354,6 +359,25 @@ public static void filterComposingCondition(String projectId, String instanceId,
354359 // [END bigtable_filters_composing_condition]
355360 // [END_EXCLUDE]
356361
362+ // [START bigtable_hw_get_with_filter]
363+ private static void readRowFilter (
364+ String projectId , String instanceId , String tableId , Filter filter ) {
365+ // Initialize client that will be used to send requests. This client only needs to be created
366+ // once, and can be reused for multiple requests.
367+ try (BigtableDataClient dataClient = BigtableDataClient .create (projectId , instanceId )) {
368+ String rowKey =
369+ Base64 .getEncoder ().encodeToString ("greeting0" .getBytes (StandardCharsets .UTF_8 ));
370+ Row row = dataClient .readRow (tableId , rowKey , filter );
371+ printRow (row );
372+ System .out .println ("Row filter completed." );
373+ } catch (IOException e ) {
374+ System .out .println (
375+ "Unable to initialize service client, as a network error occurred: \n " + e );
376+ }
377+ }
378+ // [END bigtable_hw_get_with_filter]
379+
380+ // [START bigtable_hw_scan_with_filter]
357381 private static void readFilter (
358382 String projectId , String instanceId , String tableId , Filter filter ) {
359383 // Initialize client that will be used to send requests. This client only needs to be created
@@ -365,13 +389,19 @@ private static void readFilter(
365389 for (Row row : rows ) {
366390 printRow (row );
367391 }
392+ System .out .println ("Table filter completed." );
368393 } catch (IOException e ) {
369394 System .out .println (
370- "Unable to initialize service client, as a network error occurred: \n " + e . toString () );
395+ "Unable to initialize service client, as a network error occurred: \n " + e );
371396 }
372397 }
398+ // [END bigtable_hw_scan_with_filter]
373399
400+ // [START bigtable_print_row]
374401 private static void printRow (Row row ) {
402+ if (row == null ) {
403+ return ;
404+ }
375405 System .out .printf ("Reading data for %s%n" , row .getKey ().toStringUtf8 ());
376406 String colFamily = "" ;
377407 for (RowCell cell : row .getCells ()) {
@@ -390,5 +420,6 @@ private static void printRow(Row row) {
390420 }
391421 System .out .println ();
392422 }
423+ // [END bigtable_print_row]
393424}
394425// [END bigtable_filters_print]
0 commit comments