Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New row doc, new license file, new row delete test

  • Loading branch information...
commit 02138471c4c375d2d5c9f0471a2e47766df749eb 1 parent 6323e92
@wdavidw wdavidw authored
View
15 LICENSE.md
@@ -0,0 +1,15 @@
+Software License Agreement (BSD License)
+========================================
+Copyright (c) 2008-2009, SARL Adaltas.
+
+All rights reserved.
+
+Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+- Neither the name of SARL Adaltas nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of the SARL Adaltas.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
10 README.md
@@ -5,6 +5,10 @@ Pop HBase is a PHP client to an HBase server. It use JSON Rest and the Curl exte
Its features include:
-- Server information: version, status and cluster information
-- Table manipulations: list, create, modify and delete
-- Row mipulation: Create, update, retrieve
+- *Server information:* version, status and cluster information
+- *Table manipulations:* list, create, modify and delete
+- *Row mipulation:* 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.
+
+By default, the connection is handled by the Curl base implementation ("PopHbaseConnectionCurl") and it requires PHP to be compiled with Curl support. A socket based implementation is also provided but less stable at the time.
View
40 docs/row.md
@@ -0,0 +1,40 @@
+Row operations: Create, update and list table rows in HBase
+===========================================================
+
+Those operations are handled by the class "PopHbaseTable" which can be retrieved from an instance of "PopHbase" through the "tables" property.
+
+Grab an instance of "PopHbaseRow"
+---------------------------------
+
+ $row = $hbase->tables->my_table->my_row;
+ assert($row instanceof PopHbaseTableRow);
+ assert($hbase->tables->my_table->my_row !== $row);
+
+Retrieve a column value from HBase
+----------------------------------
+
+Getting a value from HBase is achieved through the "PopHbaseTableRow->get" method and its magick shortcut. It takes a single argument, the column name, in the form of the column family followed by colons followed by the column name.
+
+ $row = $hbase->tables->my_table->my_row;
+
+ // Using the "get" method
+ $row->get('my_column_family:my_column');
+
+ // Using the magick method
+ $row->{'my_column_family:my_column'};
+
+Insert and update of a row and a column value
+---------------------------------------------
+
+In HBase, inserting and updating operation of rows and column values are the same operation.
+
+ $row = $hbase->tables->my_table->my_new_or_existing_row;
+ $row->put('my_column_family:my_column','my_value');
+
+Delete a row from an HBase table
+--------------------------------
+
+Row removal is achieved by calling the "PopHbaseRow->delete" method without any argument.
+
+ $row = $hbase->tables->my_table->my_row;
+ $row->delete();
View
17 docs/table.md
@@ -1,7 +1,7 @@
Table operations: List, create, modify and delete HBase tables
==============================================================
-Those operations are handled by the class "PopHbaseTable" which can be retrieved from an instance of "PopHbase" through the "tables" property.
+Those operations are handled by the classes "PopHbaseTables" and "PopHbaseTable" which can be retrieved from an instance of "PopHbase" through the "tables" property.
Grab an instance of "PopHbaseTables"
------------------------------------
@@ -10,6 +10,21 @@ Grab an instance of "PopHbaseTables"
assert($tables instanceof PopHbaseTables);
assert($tables === $hbase->tables);
+Grab an instance of "PopHbaseTable"
+------------------------------------
+
+ // The shorter way from "PopHbase"
+ $myTable = $hbase->table('my_table');
+ assert($myTable instanceof PopHbaseTable);
+
+ // Through the "PopHbaseTables->table" method
+ assert($hbase->tables->table('my_table) instanceof PopHbaseTable);
+ assert($hbase->tables->table('my_table) === $myTable);
+
+ // The magick way from "PopHbaseTables"
+ assert($hbase->tables->my_table instanceof PopHbaseTable);
+ assert($hbase->tables->my_table === $myTable);
+
List tables names in HBase
--------------------------
View
61 src/PopHbaseRow.php
@@ -7,7 +7,7 @@
*/
/**
- * Wrap an Hbase table
+ * Wrap an Hbase table row.
*
* @author David Worms info(at)adaltas.com
*/
@@ -22,6 +22,62 @@ public function __construct(PopHbase $hbase,$table,$key){
$this->key = $key;
}
+ public function __get($column){
+ return $this->get($column);
+ }
+
+ /**
+ * Deletes an entire row, a entire column family, or specific cell(s).
+ *
+ * Delete a entire row
+ * $hbase
+ * ->table('my_table')
+ * ->row('my_row')
+ * ->delete();
+ *
+ * Delete a entire column family
+ * $hbase
+ * ->table('my_table')
+ * ->row('my_row')
+ * ->delete('my_column_family');
+ *
+ * Delete all the cells in a column
+ * $hbase
+ * ->table('my_table')
+ * ->row('my_row')
+ * ->delete('my_column_family:my_column');
+ *
+ * Delete a specific cell
+ * $hbase
+ * ->table('my_table')
+ * ->row('my_row')
+ * ->delete('my_column_family:my_column','my_timestamp');
+ */
+ public function delete(){
+ $args = func_get_args();
+ $url = $this->table .'/'.$this->key;
+ switch(count($args)){
+ case 1;
+ // Delete a column or a column family
+ $url .= '/'.$args[0];
+ case 2:
+ // Delete a specific cell
+ $url .= '/'.$args[1];
+ }
+ return $this->hbase->request->delete($url);
+ }
+
+
+ /**
+ * Retrieve a value from a column row.
+ *
+ * Usage:
+ *
+ * $hbase
+ * ->table('my_table')
+ * ->row('my_row')
+ * ->get('my_column_family:my_column');
+ */
public function get($column){
$body = $this->hbase->request->get($this->table .'/'.$this->key.'/'.$column)->body;
if(is_null($body)){
@@ -52,7 +108,8 @@ public function put($column,$value){
))
))
);
- return $this->hbase->request->put($this->table .'/'.$this->key.'/'.$column,$value);
+ $this->hbase->request->put($this->table .'/'.$this->key.'/'.$column,$value);
+ return $this;
}
}
View
8 src/PopHbaseTable.php
@@ -21,6 +21,10 @@ public function __construct(PopHbase $hbase,$name){
$this->name = $name;
}
+ public function __get($row){
+ return $this->row($row);
+ }
+
public function create(){
call_user_func_array(
array($this->hbase->tables,'create'),
@@ -37,8 +41,8 @@ public function exists(){
return $this->hbase->tables->exists($this->name);
}
- public function row($key){
- return new PopHbaseRow($this->hbase,$this->name,$key);
+ public function row($row){
+ return new PopHbaseRow($this->hbase,$this->name,$row);
}
}
View
29 tests/row/HbaseRowDeleteTest.php
@@ -0,0 +1,29 @@
+<?php
+
+/**
+ * Copyright (c) 2008, SARL Adaltas & EDF. All rights reserved.
+ * Code licensed under the BSD License:
+ * http://www.php-pop.org/pop_config/license.html
+ */
+
+require_once dirname(__FILE__).'/../PopHbaseTestCase.php';
+
+/**
+ * Test the PopHbaseRow->get method.
+ *
+ * @author David Worms info(at)adaltas.com
+ *
+ */
+class HbaseRowDeleteTest extends PopHbaseTestCase{
+ public function testRow(){
+ $hbase = $this->hbase;
+ // Test with undefined value
+ $value = 'my_value_'.time();
+ $row = $hbase->tables->pop_hbase->row('row_test_count_1');
+ $row->put('column_test:my_column',$value);
+ $this->assertSame($value,$row->get('column_test:my_column'));
+ // Now test the delete method
+ $row->delete();
+ $this->assertNull($row->get('column_test:my_column'));
+ }
+}
View
11 tests/row/HbaseRowGetTest.php
@@ -17,9 +17,14 @@
class HbaseRowGetTest extends PopHbaseTestCase{
public function testUndefinedColumn(){
$hbase = $this->hbase;
- $value = $hbase->tables->pop_hbase
- ->row('row_test_count_1')->get('column_test:get_undefined_my_column');
- echo $value;
+ // Test with undefined value
+ $row = $hbase->tables->pop_hbase->row('row_test_count_1');
+ $value = $row->get('column_test:get_undefined_my_column');
$this->assertNull($value);
+ // Test with inserted value
+ $value = 'my_value_'.time();
+ $row->put('column_test:my_column',$value);
+ $this->assertSame($value,$row->get('column_test:my_column'));
+ $this->assertSame($value,$row->{'column_test:my_column'});
}
}
View
2  tests/row/HbaseRowPutTest.php
@@ -15,7 +15,7 @@
*
*/
class HbaseRowPutTest extends PopHbaseTestCase{
- public function testCount(){
+ public function testPut(){
$hbase = $this->hbase;
$value = 'my_value_'.time();
$row = $hbase->tables->pop_hbase->row('row_test_count_1');
Please sign in to comment.
Something went wrong with that request. Please try again.