-
Notifications
You must be signed in to change notification settings - Fork 6
/
scan.php
63 lines (50 loc) · 2.18 KB
/
scan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
$GLOBALS['THRIFT_ROOT'] = './thrift/lib/Thrift';
require_once('thrift/src/Thrift.php');
require_once($GLOBALS['THRIFT_ROOT'].'/Type/TMessageType.php');
require_once($GLOBALS['THRIFT_ROOT'].'/Type/TType.php');
require_once($GLOBALS['THRIFT_ROOT'].'/Exception/TException.php');
require_once($GLOBALS['THRIFT_ROOT'].'/Factory/TStringFuncFactory.php');
require_once($GLOBALS['THRIFT_ROOT'].'/StringFunc/TStringFunc.php');
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\ColumnDescriptor;
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 = 'note';
$filter = "QualifierFilter(>=, 'binary:1500')"; // greater than 1500
$scan = new TScan(array(
'startRow' => 'rowkey-1',
'stopRow' => 'rowkey-2',
'filterString' => $filter, 'sortColumns' => true));
$scanid = $client->scannerOpenWithScan($table, $scan, null);
$rowresult = $client->scannerGet($scanid);
// print_r($rowresult);
echo("\nrow: {$rowresult[0]->row}, cols: \n\n");
// 위에 TScan에 sortColumns 옵션을 안주면 $rowresult[0]->columns 로 접근.
$values = $rowresult[0]->sortedColumns;
// asort($values);
foreach ($values as $k=>$v) {
echo(" {$k} => {$v->value}\n");
}
$client->scannerClose($scanid);
$transport->close();
} catch (TException $e) {
print 'TException: '.$e->__toString().' Error: '.$e->getMessage()."\n";
}