博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php 从hbase 获取数据
阅读量:6603 次
发布时间:2019-06-24

本文共 3210 字,大约阅读时间需要 10 分钟。

hot3.png

<?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();

?>

 

转载于:https://my.oschina.net/u/3371661/blog/3017786

你可能感兴趣的文章
Centos(Yum源更改)
查看>>
冰球游戏大概的模块
查看>>
PHP中htmlentities和htmlspecialchars的区别
查看>>
sql分页limit
查看>>
Best Part
查看>>
【JSP EL】el表达式判断是否为null
查看>>
ClassPathXMLApplicationContext上下文加载过程
查看>>
获取所有input值 处理成json格式再利用$.post提交
查看>>
大数据存储系统三_Document store、图存储系统
查看>>
php后台对接ios,安卓,API接口设计和实践完全攻略,涨薪必备技能
查看>>
从xfire谈WebService接口化编程
查看>>
扇形进度条的应用(冷却的技能效果)
查看>>
JS模拟select下拉菜单
查看>>
线性方程组迭代求解——Jacobi迭代算法(Python实现)
查看>>
vmware workstation14永久激活密钥分享
查看>>
(旧)子数涵数·PS——水杯抠图
查看>>
java的Reference学习
查看>>
远程连接服务端电脑mysql数据库
查看>>
java虚拟机知识和 内存 堆(heap)、栈(stack)和方法区(method)
查看>>
Windows 64位操作系统下安装和配置MySQL
查看>>