Permalink
Browse files

Documentation and api improvements

  • Loading branch information...
1 parent 0213847 commit 3f555e2119a1278e8904c614b6adc2305d1f449e @wdavidw wdavidw committed Apr 15, 2010
View
@@ -7,7 +7,7 @@ Its features include:
- *Server information:* version, status and cluster information
- *Table manipulations:* list, create, modify and delete
-- *Row mipulation:* Create, update, retrieve
+- *Row access:* Create, update, retrieve
The source code has been tested agains PHP 5.2.x and PHP 5.3.x versions, however, it should also run on PHP 5.1.x versions.
View
@@ -0,0 +1,37 @@
+Connection: Connecting to an HBase server
+=========================================
+
+A new instance of "PopHbase" may be instantiated with an array containing the following properties:
+
+- *alive*
+ boolean, default to true
+ Http alive directive
+- *connection*
+ string or boolean, default to "PopHbaseConnectionCurl"
+ Class used to handle the connection.
+- *host*
+ string, optional, default to "localhost"
+ Domain or IP of the HBase Stargate server
+- *port*
+ string or int, optional, default to "8080"
+ Port of the HBase Stargate server
+- *verbose*
+ boolean or string, optional, default to "false", used by "PopHbaseConnectionCurl"
+ Outpout verbose information to stdout (or a file if value is a string)
+ about HTTP traffic
+
+The library is lazy, meaning the connection to the server will be opened only when it is really required.
+
+Creating a new connection
+-------------------------
+
+No parameter, all parameters being optional:
+
+ $hbase = new PopHbase();
+
+With user defined configuration:
+
+ $hbase = new PopHbase(array(
+ "host" => "127.0.0.1",
+ "port" => "8080",
+ ));
View
@@ -13,7 +13,7 @@ Grab an instance of "PopHbaseTables"
Grab an instance of "PopHbaseTable"
------------------------------------
- // The shorter way from "PopHbase"
+ // Directly from the "PopHbase" instance
$myTable = $hbase->table('my_table');
assert($myTable instanceof PopHbaseTable);
@@ -25,10 +25,10 @@ Grab an instance of "PopHbaseTable"
assert($hbase->tables->my_table instanceof PopHbaseTable);
assert($hbase->tables->my_table === $myTable);
-List tables names in HBase
+List table names in HBase
--------------------------
-The "PopHbaseTables->names" method takes no argument and return a list of tables names. The term "list" being a reserved keywords in PHP, we used the term "names" to call this method.
+The "PopHbaseTables->names" method takes no argument and return a list of table names. The term "list" being a reserved keywords in PHP, we used the term "names" to call this method.
$tables = $hbase->tables->names();
foreach($tables as $table){
@@ -52,15 +52,17 @@ Count the number of table in HBase
The "PopHbaseTables" class implement the PHP "Countable" interface so you can directly use the PHP "count" function while passing an instance of it as an argument.
$tables = $hbase->tables;
- assert(is_int($tables));
+ assert(is_int($tables->count()));
+ assert(is_int(count($tables)));
Create a new table in HBase
---------------------------
-The simplest way is to provide two string arguments. The first one is the table name and the second one is the column family name.
+The simplest way is to call the create method while providing two string arguments. The first one is the table name and the second one is the column family name.
- $tables = $hbase->tables;
- $tables->create("my_table","my_column_family");
+ $hbase->create("my_table","my_column_family");
+
+ $hbase->tables->create("my_table","my_column_family");
For more control on the table and column family schema configuration, the argument may take the form of an associative array. The table argument must contain the key "name" and may also contain the keys "is_meta" and "is_root". The column family arguments must contain the key "name" and may also contain the keys "blocksize", "bloomfilter", "blockcache", "compression", "length", "versions", "ttl" and "in_memory".
@@ -75,9 +77,10 @@ For more control on the table and column family schema configuration, the argume
Drop an existing table from HBase
---------------------------------
-Disabling and drop of a table is achieved through the "delete" method.
+Disabling and dropping of a table is achieved through the "delete" method.
- $tables = $hbase->tables;
- $tables->delete('my_table');
+ $hbase->delete('my_table');
+
+ $hbase->tables->delete('my_table');
View
@@ -15,7 +15,7 @@ class PopHbase{
public $options;
- public function __construct($options){
+ public function __construct($options=array()){
if(empty($options['connection'])){
$options['connection'] = 'PopHbaseConnectionCurl';
}else if (class_exists('PopHbaseConnection'.ucfirst($options['connection']))){
@@ -94,12 +94,36 @@ public function getStatusCluster(){
/**
* Shortcut to the "PopHbaseTables->table" method.
*
- * Usage
- * assert($hbase->table('my_table') instanceof PopHbaseTable);
+ * See "PopHbaseTables->table" for usage information.
*
*/
public function table($table){
return $this->tables->table($table);
}
+
+ /**
+ * Shortcut to the "PopHbaseTables->create" method.
+ *
+ * See "PopHbaseTables->create" for usage information.
+ *
+ * @param $table string Name of the table to create
+ * @param $column string Name of the column family to create
+ * @return PopHbase Current instance
+ */
+ public function create($table){
+ return call_user_func_array(array($this,'tables'),$args)->hbase;
+ }
+
+ /**
+ * Shortcut to the "PopHbaseTables->delete" method.
+ *
+ * See "PopHbaseTables->delete" for usage information.
+ *
+ * @param $table string Name of the table to delete
+ * @return PopHbase Current instance
+ */
+ public function delete($table){
+ return $this->tables->delete($table)->hbase;
+ }
}
@@ -20,12 +20,17 @@ class PopHbaseConnectionCurl implements PopHbaseConnection{
*
* Options may include:
* - *host*
- * Hbase server host, default to "localhost"
+ * Hbase server host, default to "localhost"
* - *port*
- * Hbase server port, default to "5984"
+ * Hbase server port, default to "5984"
*
- * @param $options
- * @return unknown_type
+ * Accorging to Stargate API:
+ * ./bin/hbase org.apache.hadoop.hbase.stargate.Main -p <port>
+ * ./bin/hbase-daemon.sh start org.apache.hadoop.hbase.stargate.Main -p <port>
+ * Where <port> is optional, and is the port the connector should listen on. (Default is 8080.)
+ *
+ * @param $options array Connection information
+ * @return null
*/
public function __construct(array $options = array()){
if(!isset($options['host'])){
@@ -20,19 +20,24 @@ class PopHbaseConnectionSock implements PopHbaseConnection{
*
* Options may include:
* - *host*
- * Hbase server host, default to "localhost"
+ * Hbase server host, default to "localhost"
* - *port*
- * Hbase server port, default to "5984"
+ * Hbase server port, default to "8080"
*
- * @param $options
- * @return unknown_type
+ * Accorging to Stargate API:
+ * ./bin/hbase org.apache.hadoop.hbase.stargate.Main -p <port>
+ * ./bin/hbase-daemon.sh start org.apache.hadoop.hbase.stargate.Main -p <port>
+ * Where <port> is optional, and is the port the connector should listen on. (Default is 8080.)
+ *
+ * @param $options array Connection information
+ * @return null
*/
public function __construct(array $options = array()){
if(!isset($options['host'])){
$options['host'] = 'localhost';
}
if(!isset($options['port'])){
- $options['port'] = 5984;
+ $options['port'] = 8080;
}
if(!isset($options['alive'])){
$options['alive'] = 1;
View
@@ -16,6 +16,16 @@ class PopHbaseRow{
public $hbase;
public $key;
+ /**
+ * Contruct a new row instance.
+ *
+ * The identified row does not have to be yet persisted in HBase, it
+ * will automatically be created if not yet present.
+ *
+ * @param PopHbase $hbase
+ * @param string $table
+ * @param string $key
+ */
public function __construct(PopHbase $hbase,$table,$key){
$this->hbase = $hbase;
$this->table = $table;
@@ -70,6 +70,10 @@ public function load(){
* array('name'=>'column_2'),
* array('NAME'=>'column_3'),
* array('@NAME'=>'column_4',...);
+ *
+ * @param $table string Name of the table to create
+ * @param $column string Name of the column family to create
+ * @return PopHbase Current instance
*/
public function create(){
$args = func_get_args();
@@ -9,7 +9,7 @@
require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
/**
- * Test the PopHbaseTables->create method.
+ * Test the PopHbaseTables->names method.
*
* @author David Worms info(at)adaltas.com
*

0 comments on commit 3f555e2

Please sign in to comment.