@@ -59,8 +59,6 @@ public class HelloWorld {
59
59
private static final String COLUMN_QUALIFIER_GREETING = "greeting" ;
60
60
private static final String COLUMN_QUALIFIER_NAME = "name" ;
61
61
private static final String ROW_KEY_PREFIX = "rowKey" ;
62
- private final String projectId ;
63
- private final String instanceId ;
64
62
private final String tableId ;
65
63
private final BigtableDataClient dataClient ;
66
64
private final BigtableTableAdminClient adminClient ;
@@ -80,8 +78,6 @@ public static void main(String[] args) throws Exception {
80
78
81
79
public HelloWorld (String projectId , String instanceId , String tableId ) throws IOException {
82
80
this .tableId = tableId ;
83
- this .projectId = projectId ;
84
- this .instanceId = instanceId ;
85
81
86
82
// [START bigtable_hw_connect]
87
83
// Creates the settings to configure a bigtable data client.
@@ -109,7 +105,7 @@ public void run() throws Exception {
109
105
readSingleRow ();
110
106
readSpecificCells ();
111
107
readTable ();
112
- filterLimitCellsPerCol (this . projectId , this . instanceId , tableId );
108
+ filterLimitCellsPerCol (tableId );
113
109
deleteTable ();
114
110
close ();
115
111
}
@@ -221,48 +217,32 @@ public List<Row> readTable() {
221
217
}
222
218
223
219
// [START bigtable_hw_create_filter]
224
- public static void filterLimitCellsPerCol (String projectId , String instanceId , String tableId ) {
220
+ public void filterLimitCellsPerCol (String tableId ) {
225
221
// A filter that matches only the most recent cell within each column
226
222
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 );
229
225
}
230
226
// [END bigtable_hw_create_filter]
231
227
232
228
// [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." );
247
235
}
248
236
// [END bigtable_hw_get_with_filter]
249
237
250
238
// [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 );
265
244
}
245
+ System .out .println ("Table filter completed." );
266
246
}
267
247
// [END bigtable_hw_scan_with_filter]
268
248
0 commit comments