$tablename='test';
$atrribute = array();
1.写入数据
$row = 'stu1'; //行名字
$mutations = array(
new Mutation(array(
'column' => 'cf:math',
'value' => '90'
)),
);
try {
$client->mutateRow($tablename, $row, $mutations, $atrribute);
} catch (Exception $e) {
var_dump($e);//这里自己打log
}
2.php读Hbase数据
$result = $client->getRow($tablename, $row, $atrribute);
var_dump($result);
3. php删除Hbase数据
$client->deleteAllRow($tablename, $row, $atrribute);
4. php 读取一条Hbase数据
$result = $client->getRow($tablename, $row, $atrribute);
var_dump($result);
5. php扫描Hbase里stu开头的数据
$scan = $client->scannerOpenWithPrefix($tablename, 'stu', array(),array());
$nbRows = 100;
$arr = $client->scannerGetList($scan, $nbRows);
echo 'count of result :'.count($arr)."\n";
var_dump($arr);
foreach ($arr as $k => $TRowResult) {
echo "\trow:$TRowResult->row\tcolumns(array):";
foreach ($TRowResult->columns as $key => $value) {
echo "key:$key\tvalue:$value->value\ttimestamp:$value->timestamp\n";
}
}
6. php 范围扫描 stu0 到 stu3的数据
$scan = $client->scannerOpenWithStop($tablename, 'stu0', 'stu3', array(), array());
$nbRows = 100;
$arr = $client->scannerGetList($scan, $nbRows);
echo 'count of result :'.count($arr)."\n";
var_dump($arr);
foreach ($arr as $k => $TRowResult) {
echo "\trow:$TRowResult->row\tcolumns(array):";
foreach ($TRowResult->columns as $key => $value) {
echo "key:$key\tvalue:$value->value\ttimestamp:$value->timestamp\n";
}
}
7. Hbase的 Increment 操作
一种原子操作,每次增加一定数字
$row = 'stu7';
try {
$newCount = $client->atomicIncrement($tablename, $row, 'cf:count', 1);
} catch (Exception $e) {
var_dump($e);
}
echo "new count $newCount\n";
8. php写入一个long型数据到hbase
$row = 'stu6';
$value = pack("J", 4567);
$mutations = array(
new Mutation(array(
'column' => 'cf:math',
'value' => $value
)),
);
try {
$client->mutateRow($tablename, $row, $mutations, $atrribute);
} catch (Exception $e) {
var_dump($e);
}
echo "---read data and print it as long ---\n";
$result = $client->getRow($tablename, $row, $atrribute);
foreach ($result[0]->columns as $key => $value) {
$count = unpack("J*mycount", $value->value);
var_dump($count);
}
You must be logged in to post a comment.
除了这些操作,还没有文档之类的呢