Database Reference
In-Depth Information
To create a table, we need to create an instance of HBaseAdmin and then ask it to create
the table named test with a single column family named data . In our example, our
table schema is the default. We could use methods on HTableDescriptor and
HColumnDescriptor to change the table schema. Next, the code asserts the table was
actually created, and throws an exception if it wasn't.
To operate on a table, we will need an instance of HTable , which we construct by
passing it our Configuration instance and the name of the table. We then create Put
objects in a loop to insert data into the table. Each Put puts a single cell value of
value n into a row named row n on the column named data: n , where n is from 1 to 3.
The column name is specified in two parts: the column family name, and the column fam-
ily qualifier. The code makes liberal use of HBase's Bytes utility class (found in the
org.apache.hadoop.hbase.util package) to convert identifiers and values to the
byte arrays that HBase requires.
Next, we create a Get object to retrieve and print the first row that we added. Then we
use a Scan object to scan over the table, printing out what we find.
At the end of the program, we clean up by first disabling the table and then deleting it (re-
call that a table must be disabled before it can be dropped).
Search WWH ::




Custom Search