19
19
*/
20
20
package com .example .cloud .bigtable .helloworld ;
21
21
22
- // [START bigtable_hw_imports ]
22
+ // [START bigtable_hw_imports_hbase ]
23
23
import com .google .cloud .bigtable .hbase .BigtableConfiguration ;
24
24
25
25
import org .apache .hadoop .hbase .HColumnDescriptor ;
36
36
import org .apache .hadoop .hbase .util .Bytes ;
37
37
38
38
import java .io .IOException ;
39
- // [END bigtable_hw_imports ]
39
+ // [END bigtable_hw_imports_hbase ]
40
40
41
41
/**
42
42
* A minimal application that connects to Cloud Bigtable using the native HBase API and performs
@@ -57,25 +57,25 @@ public class HelloWorld {
57
57
/** Connects to Cloud Bigtable, runs some basic operations and prints the results. */
58
58
private static void doHelloWorld (String projectId , String instanceId ) {
59
59
60
- // [START bigtable_hw_connect ]
60
+ // [START bigtable_hw_connect_hbase ]
61
61
// Create the Bigtable connection, use try-with-resources to make sure it gets closed
62
62
try (Connection connection = BigtableConfiguration .connect (projectId , instanceId )) {
63
63
64
64
// The admin API lets us create, manage and delete tables
65
65
Admin admin = connection .getAdmin ();
66
- // [END bigtable_hw_connect ]
66
+ // [END bigtable_hw_connect_hbase ]
67
67
68
68
try {
69
- // [START bigtable_hw_create_table ]
69
+ // [START bigtable_hw_create_table_hbase ]
70
70
// Create a table with a single column family
71
71
HTableDescriptor descriptor = new HTableDescriptor (TableName .valueOf (TABLE_NAME ));
72
72
descriptor .addFamily (new HColumnDescriptor (COLUMN_FAMILY_NAME ));
73
73
74
74
print ("Create table " + descriptor .getNameAsString ());
75
75
admin .createTable (descriptor );
76
- // [END bigtable_hw_create_table ]
76
+ // [END bigtable_hw_create_table_hbase ]
77
77
78
- // [START bigtable_hw_write_rows ]
78
+ // [START bigtable_hw_write_rows_hbase ]
79
79
// Retrieve the table we just created so we can do some reads and writes
80
80
Table table = connection .getTable (TableName .valueOf (TABLE_NAME ));
81
81
@@ -100,18 +100,18 @@ private static void doHelloWorld(String projectId, String instanceId) {
100
100
put .addColumn (COLUMN_FAMILY_NAME , COLUMN_NAME , Bytes .toBytes (GREETINGS [i ]));
101
101
table .put (put );
102
102
}
103
- // [END bigtable_hw_write_rows ]
103
+ // [END bigtable_hw_write_rows_hbase ]
104
104
105
- // [START bigtable_hw_get_by_key ]
105
+ // [START bigtable_hw_get_by_key_hbase ]
106
106
// Get the first greeting by row key
107
107
String rowKey = "greeting0" ;
108
108
Result getResult = table .get (new Get (Bytes .toBytes (rowKey )));
109
109
String greeting = Bytes .toString (getResult .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME ));
110
110
System .out .println ("Get a single greeting by row key" );
111
111
System .out .printf ("\t %s = %s\n " , rowKey , greeting );
112
- // [END bigtable_hw_get_by_key ]
112
+ // [END bigtable_hw_get_by_key_hbase ]
113
113
114
- // [START bigtable_hw_scan_all ]
114
+ // [START bigtable_hw_scan_all_hbase ]
115
115
// Now scan across all rows.
116
116
Scan scan = new Scan ();
117
117
@@ -121,14 +121,14 @@ private static void doHelloWorld(String projectId, String instanceId) {
121
121
byte [] valueBytes = row .getValue (COLUMN_FAMILY_NAME , COLUMN_NAME );
122
122
System .out .println ('\t' + Bytes .toString (valueBytes ));
123
123
}
124
- // [END bigtable_hw_scan_all ]
124
+ // [END bigtable_hw_scan_all_hbase ]
125
125
126
- // [START bigtable_hw_delete_table ]
126
+ // [START bigtable_hw_delete_table_hbase ]
127
127
// Clean up by disabling and then deleting the table
128
128
print ("Delete the table" );
129
129
admin .disableTable (table .getName ());
130
130
admin .deleteTable (table .getName ());
131
- // [END bigtable_hw_delete_table ]
131
+ // [END bigtable_hw_delete_table_hbase ]
132
132
} catch (IOException e ) {
133
133
if (admin .tableExists (TableName .valueOf (TABLE_NAME ))) {
134
134
print ("Cleaning up table" );
0 commit comments