php 从hbase 获取数据 原

<?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 Thrift\Protocol\TBinaryProtocol; use Thrift\Transport\TBufferedTransport; use Thrift\Transport\TSocket; use Hbase\HbaseClient; use Hbase\ColumnDescriptor; use Hbase\Mutation; $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->row\tcolumns(array):"; //     foreach ($TRowResult->columns as $key => $value) { //         echo "key:$key\tvalue:$value->value\ttimestamp:$value->timestamp\n"; //     } // }

 # 过滤器 $filter = array();

$filter[] = "ValueFilter(=,'substring:cat_id:7|sub_cat:65')"; $filterString = implode(" AND ", $filter); $scanFilter = new \Hbase\TScan(); $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({});

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

扫码关注云+社区

领取腾讯云代金券