HBaseConfiguration.create(); //Create a configuration file
Configuration.set(String key, String value); //Add a key to the configuration
ConnectionFactory.createConnection(HBaseConfiguration configuration); //Connects to HBase
Connection.getAdmin(); //Instanciate a new Admin
new HTableDescriptor(Table.valueOf(String tableName));; //Create a table descriptor
HTableDescriptor.addFamily(new HColumnDescriptor(String familyName)); //Add a family to the table descriptor
Admin.createTable(HTableDescriptor descriptor); //Create a table as described in the descriptor
Admin.deleteTable(TableName.valueOf(String tableName)); //Delete a table
Connection.getTable(TableName.valueOf(String tableName)); //Get a Table Object
new Get(Bytes.toBytes(String row_key)); //Create a new Get
table.get(Get get) //Returns a Result
new Put(String row_key); //Create a new Put
table.put(Put put); //Insert the row(s)
new Scan(); //Create new Scan
table.getScanner(Scan scan); //Return a ResultScanner
new Delete(Bytes.toBytes(String row_key)); //Create a new Delete
table.delete(Delete delete); //Delete a row from the table
Parameter | Possible Values |
---|---|
CompareOp | CompareOp.EQUAL , CompareOp.GREATER , CompareOp.GREATER_OR_EQUAL , CompareOp.LESS , CompareOp.LESS_OR_EQUAL , CompareOp.NOT_EQUAL , CompareOp.NO_OP (no operation) |
This topic show various examples of how to use the Java API for HBase. In this topic you will learn to create and delete a table, insert, query and delete rows from a table but also use the Scans filters.
You will notice than many methods of this API take Bytes as parameters for example the columnFamily name, this is due to HBase implementation. For optimization purpose, instead of storing the values as String, Integer or whatever, it stores a list of Bytes, that is why you need to parse all those values as Bytes. To do this, the easiest method is to use Bytes.toBytes(something)
.
Please feel free to notice if you see any mistake or misunderstanding.