首页 > php > php操作hbase

php操作hbase

作者:bin

这里将介绍php如何使用thrift进行操作php。

在阅读这篇文章前,建议先学习一些hbase shell的基础使用

这里提供thrif2的php框架以供使用、测试

这里仅测试scan方式,其他方法类似,可自行查看(THBaseService.php/get、put、scan等方法的使用)

require_once('hbase/THBaseService.php'); 

require_once('hbase/Types.php'); 

$host = '192.168.1.244';

$port = '9090';

$socket = new TSocket($host, $port);

$socket->setSendTimeout(5000);

$socket->setRecvTimeout(10000);

$this->transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($this->transport); 
$this->client = new THBaseServiceClient($protocol); 
$this->transport->open()

//上面的代码几乎固定, 只需要修改thrift2的host和port 
/*倒序查询user表从1-100行,中的第一行中族f1中的name列值*/

$table = 'user'; //你需要查的表名 $limit = 1; //限制多少输出

$start_row = '1'; //从第几行开始查 $stop_row = '100'; //结束行

$column_arr['family'] = 'f1' ; //表中哪个族 
$column_arr['qualifier'] = 'name'; //哪一列 
$column_1[] = new TColumn($column_arr);

$scan_val = array(
 'startRow' =>$stop_row,
 'stopRow' => $start_row,
 'columns' => $column_1 ,
 'reversed' => true
);

$scan = new TScan($scan_val);

$ret = $this->client->getScannerResults($table, $scan, $limit); 

//记得关闭 
$this->transport->close();

var_dump($ret);

您必须 [ 登录 ] 才能发表留言!