@@ -59,8 +59,6 @@ public class HelloWorld {
5959 private static final String COLUMN_QUALIFIER_GREETING = "greeting" ;
6060 private static final String COLUMN_QUALIFIER_NAME = "name" ;
6161 private static final String ROW_KEY_PREFIX = "rowKey" ;
62- private final String projectId ;
63- private final String instanceId ;
6462 private final String tableId ;
6563 private final BigtableDataClient dataClient ;
6664 private final BigtableTableAdminClient adminClient ;
@@ -80,8 +78,6 @@ public static void main(String[] args) throws Exception {
8078
8179 public HelloWorld (String projectId , String instanceId , String tableId ) throws IOException {
8280 this .tableId = tableId ;
83- this .projectId = projectId ;
84- this .instanceId = instanceId ;
8581
8682 // [START bigtable_hw_connect]
8783 // Creates the settings to configure a bigtable data client.
@@ -109,7 +105,7 @@ public void run() throws Exception {
109105 readSingleRow ();
110106 readSpecificCells ();
111107 readTable ();
112- filterLimitCellsPerCol (this . projectId , this . instanceId , tableId );
108+ filterLimitCellsPerCol (tableId );
113109 deleteTable ();
114110 close ();
115111 }
@@ -221,48 +217,32 @@ public List<Row> readTable() {
221217 }
222218
223219 // [START bigtable_hw_create_filter]
224- public static void filterLimitCellsPerCol (String projectId , String instanceId , String tableId ) {
220+ public void filterLimitCellsPerCol (String tableId ) {
225221 // A filter that matches only the most recent cell within each column
226222 Filter filter = FILTERS .limit ().cellsPerColumn (1 );
227- readRowFilter (projectId , instanceId , tableId , filter );
228- readFilter (projectId , instanceId , tableId , filter );
223+ readRowFilter (tableId , filter );
224+ readFilter (tableId , filter );
229225 }
230226 // [END bigtable_hw_create_filter]
231227
232228 // [START bigtable_hw_get_with_filter]
233- private static void readRowFilter (
234- String projectId , String instanceId , String tableId , Filter filter ) {
235- // Initialize client that will be used to send requests. This client only needs to be created
236- // once, and can be reused for multiple requests.
237- try (BigtableDataClient dataClient = BigtableDataClient .create (projectId , instanceId )) {
238- String rowKey =
239- Base64 .getEncoder ().encodeToString ("greeting0" .getBytes (StandardCharsets .UTF_8 ));
240- Row row = dataClient .readRow (tableId , rowKey , filter );
241- printRow (row );
242- System .out .println ("Row filter completed." );
243- } catch (IOException e ) {
244- System .out .println (
245- "Unable to initialize service client, as a network error occurred: \n " + e );
246- }
229+ private void readRowFilter (String tableId , Filter filter ) {
230+ String rowKey =
231+ Base64 .getEncoder ().encodeToString ("greeting0" .getBytes (StandardCharsets .UTF_8 ));
232+ Row row = dataClient .readRow (tableId , rowKey , filter );
233+ printRow (row );
234+ System .out .println ("Row filter completed." );
247235 }
248236 // [END bigtable_hw_get_with_filter]
249237
250238 // [START bigtable_hw_scan_with_filter]
251- private static void readFilter (
252- String projectId , String instanceId , String tableId , Filter filter ) {
253- // Initialize client that will be used to send requests. This client only needs to be created
254- // once, and can be reused for multiple requests.
255- try (BigtableDataClient dataClient = BigtableDataClient .create (projectId , instanceId )) {
256- Query query = Query .create (tableId ).filter (filter );
257- ServerStream <Row > rows = dataClient .readRows (query );
258- for (Row row : rows ) {
259- printRow (row );
260- }
261- System .out .println ("Table filter completed." );
262- } catch (IOException e ) {
263- System .out .println (
264- "Unable to initialize service client, as a network error occurred: \n " + e );
239+ private void readFilter (String tableId , Filter filter ) {
240+ Query query = Query .create (tableId ).filter (filter );
241+ ServerStream <Row > rows = dataClient .readRows (query );
242+ for (Row row : rows ) {
243+ printRow (row );
265244 }
245+ System .out .println ("Table filter completed." );
266246 }
267247 // [END bigtable_hw_scan_with_filter]
268248
0 commit comments