Пример #1
0
$client->mutateRow($tableName, $row1, $mutations1, $attributes);
echo "-------write row {$row1} ---\r\n";
//update row
$client->mutateRow($tableName, $row, $mutations, $attributes);
//get column data
$row_name = $time;
$fam_col_name = 'score:a';
$arr = $client->get($tableName, $row_name, $fam_col_name, $attributes);
// $arr = array
foreach ($arr as $k => $v) {
    // $k = TCell
    echo " ------ get one : value = {$v->value} , <br>  ";
    echo " ------ get one : timestamp = {$v->timestamp}  <br>";
}
echo "----------\r\n";
$arr = $client->getRow($tableName, $row_name, $attributes);
// $client->getRow return a array
foreach ($arr as $k => $TRowResult) {
    // $k = 0 ; non-use
    // $TRowResult = TRowResult
    var_dump($TRowResult);
}
echo "----------\r\n";
/******
  //no test
  public function scannerOpenWithScan($tableName, \Hbase\TScan $scan, $attributes);

  public function scannerOpen($tableName, $startRow, $columns, $attributes);
  public function scannerOpenWithStop($tableName, $startRow, $stopRow, $columns, $attributes);
  public function scannerOpenWithPrefix($tableName, $startAndPrefix, $columns, $attributes);
  public function scannerOpenTs($tableName, $startRow, $columns, $timestamp, $attributes);
Пример #2
0
$mutations = array(new Mutation(array('column' => 'entry:foo', 'value' => $valid)));
// 多记录批量提交(200提交一次时测试小记录大概在5000/s左右):  $rows = array('timestamp'=>$timestamp, 'columns'=>array('txt:col1'=>$col1, 'txt:col2'=>$col2, 'txt:col3'=>$col3));  $records = array(rowkey=>$rows,...);  $batchrecord = array();  foreach ($records as $rowkey => $rows) {      $timestamp = $rows['timestamp'];      $columns = $rows['columns'];      // 生成一条记录      $record = array();      foreach($columns as $column => $value) {          $col = new Mutation(array('column'=>$column, 'value'=>$value));          array_push($record, $col);      }      // 加入记录数组      $batchTmp = new BatchMutation(array('row'=>$rowkey, 'mutations'=>$record));      array_push($batchrecord, $batchTmp);  }  $ret = $hbase->mutateRows('test', $batchrecord);
$client->mutateRow($t, $row, $mutations, null);
$table_name = "table1";
$row_name = 'row_name';
$fam_col_name = 'entry:foo';
$arr = $client->get($table_name, $row_name, $fam_col_name, null);
// $arr = array
foreach ($arr as $k => $v) {
    // $k = TCell
    echo "value = {$v->value} , <br>  ";
    echo "timestamp = {$v->timestamp}  <br>";
}
$table_name = "table1";
$row_name = "row_name";
$arr = $client->getRow($table_name, $row_name, null);
// $client->getRow return a array
foreach ($arr as $k => $TRowResult) {
    // $k = 0 ; non-use
    // $TRowResultTRowResult = TRowResult
    var_dump($TRowResult);
}
//scannerOpenWithStop($tableName, $startRow, $stopRow, $columns);
$table_name = 'zTest';
$startRow = "9-9-20120627-";
$stopRow = "9-9-20120627_";
$columns = array('info:');
$result = $client->scannerOpenWithStop($table_name, $startRow, $stopRow, $columns, null);
while (true) {
    $record = $client->scannerGet($result);
    if ($record == null) {
Пример #3
0
require_once $GLOBALS['THRIFT_ROOT'] . '/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'] . '/Protocol/TBinaryProtocol.php';
require_once 'thrift/lib/HBase/Hbase.php';
require_once 'thrift/lib/HBase/Types.php';
use Thrift\Transport\TSocket;
use Thrift\Transport\TBufferedTransport;
use Thrift\Protocol\TBinaryProtocol;
use Hbase\HbaseClient;
use Hbase\Mutation;
use Hbase\TScan;
$socket = new TSocket('localhost', 9090);
$socket->setSendTimeout(10000);
// Ten seconds (too long for production, but this is just a demo ;)
$socket->setRecvTimeout(20000);
// Twenty seconds
$transport = new TBufferedTransport($socket);
$protocol = new TBinaryProtocol($transport);
$client = new HbaseClient($protocol);
try {
    $transport->open();
    $table = 'tablename';
    $rowkey = 'rowkey';
    $column = 'columnfamily:column';
    print_r($client->getRow($table, $rowkey, null));
    print_r($client->get($table, $rowkey, $column, null));
    $transport->close();
} catch (TException $e) {
    print 'TException: ' . $e->__toString() . ' Error: ' . $e->getMessage() . "\n";
}