1 $GLOBALS['THRIFT_ROOT'] = '/home/thrift';
2 require_once $GLOBALS['THRIFT_ROOT'].'/Thrift.php';
3 require_once $GLOBALS['THRIFT_ROOT'].'/protocol/TBinaryProtocol.php';
4 require_once $GLOBALS['THRIFT_ROOT'].'/transport/TSocket.php';
5 require_once $GLOBALS['THRIFT_ROOT'].'/transport/THttpClient.php';
6 require_once $GLOBALS['THRIFT_ROOT'].'/transport/TBufferedTransport.php';
7 require_once $GLOBALS['THRIFT_ROOT'].'/packages/Hbase/Hbase.php';
8 require_once($GLOBALS['THRIFT_ROOT'].'/packages/hadoopfs/ThriftHadoopFileSystem.php');
9
10 $socket = new TSocket(192.168.1.4, 9091);
11 $socket->setSendTimeOut(20000);
12 $socket->setRecvTimeOut(20000);
13 $transport = new TBufferedTransport($socket);
14 $protocol = new TBinaryProtocol($transport);
15 $hbase = new HbaseClient($protocol);
16 $transport->open();
17
18 // 在这里实现功能
19
20 $transport->close();
21
22 // 多记录批量提交(200提交一次时测试小记录大概在5000/s左右):
23 $rows = array('timestamp'=>$timestamp, 'columns'=>array('txt:col1'=>$col1, 'txt:col2'=>$col2, 'txt:col3'=>$col3));
24 $records = array(rowkey=>$rows,...);
25 $batchrecord = array();
26 foreach ($records as $rowkey => $rows) {
27 $timestamp = $rows['timestamp'];
28 $columns = $rows['columns'];
29 // 生成一条记录
30 $record = array();
31 foreach($columns as $column => $value) {
32 $col = new Mutation(array('column'=>$column, 'value'=>$value));
33 array_push($record, $col);
34 }
35 // 加入记录数组
36 $batchTmp = new BatchMutation(array('row'=>$rowkey, 'mutations'=>$record));
37 array_push($batchrecord, $batchTmp);
38 }
39 $ret = $hbase->mutateRows('test', $batchrecord);
40
41 // 单记录提交(1000/s左右)
42 $mutation = array(new Mutation(array('column'=>'txt:col1', 'value'=>$col1)),
43 new Mutation(array('column'=>'txt:col2', 'value'=>$col2)),
44 new Mutation(array('column'=>'txt:col3', 'value'=>$col3)));
45 $hbase->mutateRow('test', $rowkey, $mutation);
46
47 // 扫描记录
48 $result = $hbase->scannerOpenWithStop($table, $startKey, $endKey, $columns);
49 while (true) {
50 $record = $hbase->scannerGet($result);
51 if ($record == NULL) {
52 break;
53 }
54 $recordArray = array();
55 foreach($record as $TRowResult) {
56 $row = $TRowResult->row;
57 $column = $TRowResult->columns;
58 foreach($column as $family_column=>$cell) {
59 $recordArray[$family_column] = $cellVal;
60 }
61 $resultArray[] = $recordArray;
62 }
63 }
64 print_r($resultArray);
65
66 // 以下记录从别人处(佛祖球球)拷贝,把几个接口补全,(未测试...)
67
68 // 列出hbase 裡的所有 table
69 echo( "listing tables...\n" );
70 $tables = $client->getTableNames();
71 sort( $tables );
72 foreach ( $tables as $name )
73 {
74 echo $name."\n";
75 }
76
77 // 刪除table
78 $name = "test2";
79 if($client->isTableEnabled($name))
80 {
81 echo "关闭".$name."资料表\n";
82 $client->disableTable($name);
83 }
84 echo "刪除中...\n";
85 $client->deleteTable($name);
86 echo "刪除完成";
87
88 // 新增table
89 $columns = array(new ColumnDescriptor(array('name' => 'name:')),
90 new ColumnDescriptor(array('name'=> 'scores:',)));
91 $t = "test2";
92 echo("creating table: {$t}\n");
93 try
94 {
95 $client->createTable( $t, $columns );
96 }
97 catch (AlreadyExists $ae)
98 {
99 echo( "WARN: {$ae->message}\n" );
100 }
101
102 //列出table內的column family
103 $t = "results";
104 echo("column families in {$t}:\n");
105 $descriptors = $client->getColumnDescriptors( $t );
106 asort( $descriptors );
10
详细解决方案
php操作hbase例证
热度:162 发布时间:2016-04-28 23:16:34.0
相关解决方案
- HBase 序言
- Hbase 应用 -常用-
- Hbase + Mapreduce + eclipse范例
- HBase Java Api Eclipse开发(4)
- 【hbase】——bulk load导入数据时value=\x00\x00\x00\x01有关问题解析
- HBase Thrift 0.5.0 + PHP 五 安裝設定
- 高速理解 Phoenix : SQL on HBASE
- 凤凰错误:hbase 表未定义,即使它存在
- 如何创建 2 个以上的 HBase 表?
- HBase Scan基于特定的HFile作为根
- HBase:HBase的集群环境搭建
- Apache HBase rowKey设计技巧
- org.apache.hadoop.hbase.ipc.ServerNotRunningYetException: Server is not running yet
- HBase Region自动切分的所有细节都在这里了
- Windows Hbase Docker实践
- 1.12 Flink HBase SQL 连接器
- Hbase(三) hbase协处理器与二级索引
- hbase--HBase 常用Shell命令
- hbase--Hbase 建表基本命令总结
- hbase--Hbase原理、基本概念、基本架构
- Hadoop学习笔记(四)-- HBase
- hbase 启动时 Name or service not known -完美解决
- 【HBase】安装HBase集群(3台主机)
- HBase 常见shell指令
- Spark踩坑记——数据库(Hbase+Mysql)
- spark-streaming连接hive+HBase
- janusGraph+hbase+es搭建踩坑记录
- Hadoop 3.0 zookeeper spark hive hbase scala搭建 集群搭建
- hbase shell 操作失败查看日志遇到的一个bug
- HBase idea Java客户端操作