Hbase rest方式获取指定key范围内的值
代码如下:
<?php
class Monitor_Hbase{
private $rest_host = "http://10.99.90.39:8130/";//rest地址
private $ch;
function __construct(){ }
function post($url, $data){
$ch = curl_init();
$header_str = array("Content-Type: application/json");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'put');
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt ($ch, CURLOPT_HTTPHEADER , $header_str );
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, 1); $output = curl_exec($ch);
curl_close($ch);
return $output;
} function rest($url){
$ch = curl_init();
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Accept: application/json"));
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
} function get_range_data($table, $startRow, $endRow){
$startRow = base64_encode($startRow);
$endRow = base64_encode($endRow);
$data = sprintf('{"startRow":"%s","endRow":"%s"}',$startRow,$endRow);
$output = $this->post($this->rest_host.$table."/scanner",$data);
$output_array = explode("\r\n",$output);
$location = "";
foreach($output_array as $item){
if(strpos($item, ":")>-1){
$tmp = explode(": ",$item);
if($tmp[0] === 'Location'){
$location = $tmp[1];
} }
}
$result = $this->rest($location);
$f = ($this->prase_data(json_decode($result, true)));
return $f;
} function get_data($table, $key, $coloum){
$param = urlencode($table).'/'.urlencode($key);
if(!empty($coloum)){
$param = $param.'/'.urlencode($coloum);
}
$url = $this->rest_host.$param;
$output = $this->rest($url);
return $this->prase_data(json_decode($output,true));
} function prase_data($raw){
$result = array();
$rows = $raw['Row'];
//$raw = $raw['Row'][0]['Cell'];
foreach($rows as $row){
$key = base64_decode($row['key']);
foreach ($row['Cell'] as $item){
$col = base64_decode($item['column']);
$value = base64_decode($item['$']);
$result[$key][$col]=$value;
}
}
return $result;
} } $a = new Monitor_Hbase();
$b = $a->get_range_data('map_mobile_lighttpd_slowcount','mobile_all_201411111005','mobile_all_201411111030');
//$b = $a->get_data("nuomi_lixian_daily_count","20141026_CMNET_2G_Android_5.2.1_*","");
//$b = $a->get_data("nuomi_lixian_daily_count","20141016_ALL_CMNET_2G_Android_5.2.0","");
var_dump($b);
Hbase rest方式获取指定key范围内的值的更多相关文章
- 【转载】C#中List集合使用GetRange方法获取指定索引范围内的所有值
在C#的List集合中有时候需要获取指定索引位置范围的元素对象来组成一个新的List集合,此时就可使用到List集合的扩展方法GetRange方法,GetRange方法专门用于获取List集合指定范围 ...
- 【NX二次开发】获取指定矩阵标识的矩阵值
函数:UF_CSYS_ask_matrix_values () 函数说明:获取指定矩阵标识的矩阵值. 用法: #include <uf.h> #include <uf_csys.h& ...
- 如何从二维数组中的多个key中获取指定key的值?
精华 LOVEME96 2016-10-21 10:40:19 浏览(1512) 回答(3) 赞(0) 新手求教:二维数组中一般会有多个key,如果我们要获得指定key的值,应该怎么做? 问题标签: ...
- 8 Hbase get方式获取数据
package com.hikvision.hbase.vertify.test; import org.apache.hadoop.conf.Configuration; import org.ap ...
- springMVC中不通过注解方式获取指定Service的javabean
如TestService,其实现为TestServiceImpl,则可以通过 TestService testService = (TestService)SpringContextHolder.ge ...
- 获取指定key对应的node节点信息
需求:之前写的脚本(https://www.cnblogs.com/imdba/p/10197192.html),每个node上都只有一个slot段范围的情况,本次通过测试,实现了,任意段范围的获取方 ...
- Java 获取指定日期范围内的每个月,每季度,每一年
/** *根据时间范围获得月份集 * @return */ public static List<String> getRangeSet(String beg ...
- c# json转换成dynamic对象,然后在dynamic对象中动态获取指定字符串列表中的值
using Newtonsoft.Json;using System;using System.Collections.Generic;using System.Linq;using System.T ...
- sql server 获取自增列下一个值或者获取指定表的主键值
IDENT_CURRENT('TableName')为当前的最大标识值, IDENT_INCR('TableName')为设置的标识值增量, 两者相加即为下一个标识值 如: SELECT IDENT_ ...
随机推荐
- 【转】C++ 单例模式
http://blog.csdn.net/hackbuteer1/article/details/7460019 单例的一般实现比较简单,下面是代码和UML图.由于构造函数是私有的,因此无法通过构造函 ...
- 30岁IT男连续工作一个月 突然失聪
连续开发软件一个月,30 岁男子突然听不见声音了.近日,浙江省中山医院针灸科主任高宏主任中医师接诊了这名患者.高主任说,现在很多年轻人工作压力大,得突发性耳聋的越来越多,这种病听着不是威胁生命的大病, ...
- 线程间操作无效: 从不是创建控件“”的线程访问它~~~的解决方法~ 线程间操作无效: 从不是创建控件“Control Name'”的线程访问它问题的解决方案及原理分析
看两个例子,一个是在一个进程里设置另外一个进程中控件的属性.另外一个是在一个进程里获取另外一个进程中控件的属性. 第一个例子 最近,在做一个使用线程控制下载文件的小程序(使用进度条控件显示下载进度)时 ...
- [SQL] 要查询9 月份的数据中的任意时间段,可能是一个月的,也可能是1日到15日的
SELECT * FROM [表名] WHERE datediff(month,[列名],
- convert NameValueCollection/Dictionary<string, object> to JSON string
public static class WebExtension { public static T Decode<T>(this RequestBase res) { Type type ...
- HDU 4292 Food
Food Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- jmeter随笔(10)-中文url编码问题
坚持分享,坚持总结,技术需要时间的积累和练习,对jmeter实践的点滴的记录,这里分享交流,仅供参考和讨论,有想法的欢迎留言.谈论,手机上图片如果不清晰,请点击[阅读原文]查看. 1技巧1:后台数据h ...
- C程序之修改Windows的控制台颜色(转载)
Windows的CMD可以和Linux下的终端一样可以有五颜六色,目前我在网上找到2种方法可以修改Windows的CMD,当然都是在代码中修改的.在“CMD”->“属性”->“颜色”,这种 ...
- 翻译「C++ Rvalue References Explained」C++右值引用详解 Part8:Perfect Forwarding(完美转发):解决方案
本文为第八部分,目录请参阅概述部分:http://www.cnblogs.com/harrywong/p/cpp-rvalue-references-explained-introduction.ht ...
- OpenGL ES学习笔记(一)——基本用法、绘制流程与着色器编译
首先声明下,本文为笔者学习<OpenGL ES应用开发实践指南(Android卷)>的笔记,涉及的代码均出自原书,如有需要,请到原书指定源码地址下载. 在Android.iOS等移动平台上 ...