<?php ini_set('display_errors', E_ALL); $GLOBALS['THRIFT_ROOT'] = "/home/t_qmw/project_hbase"; /* Dependencies. In the proper order. */ require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TTransport.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TSocket.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TProtocol.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TBinaryProtocol.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Protocol/TBinaryProtocolAccelerated.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Transport/TBufferedTransport.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Type/TMessageType.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Factory/TStringFuncFactory.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/StringFunc/TStringFunc.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/StringFunc/Core.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Type/TType.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Exception/TException.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Exception/TTransportException.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/Thrift/Exception/TProtocolException.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/gen-php/Hbase/Types.php'; require_once $GLOBALS['THRIFT_ROOT'] . '/gen-php/Hbase/Hbase.php'; use ThriftProtocolTBinaryProtocol; use ThriftTransportTBufferedTransport; use ThriftTransportTSocket; use HbaseHbaseClient; use HbaseColumnDescriptor; use HbaseMutation; $host='localhost'; $port='9090'; $socket = new TSocket($host, $port); $socket->setSendTimeout(10000); // 发送超时,单位毫秒 $socket->setRecvTimeout(20000); // 接收超时,单位毫秒 $transport = new TBufferedTransport($socket); $protocol = new TBinaryProtocol($transport); $client = new HbaseClient($protocol); $transport->open(); ####列出表#### // echo "----list tables----n"; $tables = $client->getTableNames(); // var_dump($tables); // foreach ($tables as $name) { // var_dump($tables); // } $table='shop:filter';
// $startRow='1'; // $scan = $client->scannerOpen($tablename, null, array ('column' => 'attr_id:1337', 'column'=>'attr_id:1443'), null); // // $scan = $client->scannerOpen($tablename, $startRow, $columns, null); // $nbRows = 4000; // $arr = $client->scannerGetList($scan, $nbRows); // echo 'count of result :'.count($arr)."n"; // var_dump($arr); // foreach ($arr as $k => $TRowResult) { // echo "trow:$TRowResult->rowtcolumns(array):"; // foreach ($TRowResult->columns as $key => $value) { // echo "key:$keytvalue:$value->valuettimestamp:$value->timestampn"; // } // }
# 过滤器 $filter = array();
$filter[] = "ValueFilter(=,'substring:cat_id:7|sub_cat:65')"; $filterString = implode(" AND ", $filter); $scanFilter = new HbaseTScan(); $scanFilter->columns=array('attr_id:1325','attr_id:1356','brand_id:94');
$scanFilter->filterString =$filterString;
$scanFilter->startRow = 'p:1'; $scanFilter->stopRow = 'p:5000';
// $scanFilter->columns = array('column' => 'author'); # 指定返回列族
$scan = $client->scannerOpenWithScan($table, $scanFilter, array()); $ret = $client->scannerGetList($scan,20); //2代表数量 var_dump($ret);
$transport->close(); ?>
(adsbygoogle = window.adsbygoogle || []).push({});