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_ ...
随机推荐
- Python中split()函数的用法及实际使用示例
Python中split()函数,通常用于将字符串切片并转换为列表. 一.函数说明: split():语法:str.split(str="",num=string.count(st ...
- pedagogical
在线考试 // '+this+''; }); //alert(错了); $("#ans").html(html); } function clk(obj){ var inp ...
- 转-Android微信支付
http://blog.fangjie.info/android微信支付/ Android微信支付 2014-08-09 一.使用微信官方的提供的demo里的appid等 1.微信接口上手指南:(从“ ...
- AD7190学习笔记
1 建议SCL空闲时会高电平. 2复位:上电后连续输入40个1(时钟周期)复位到已知状态,并等待500us后才能访问串行接口,用于SCLK噪音导致的同步. 3单次转换与连续转换(连续读取):每次转换是 ...
- Xshell5最新版激活
Xshell是一个用于MS Windows平台的强大的SSH,TELNET,和RLOGIN终端仿真软件.它使得用户能轻松和安全地从Windows PC上访问Unix/Linux主机. 以上内容全部为广 ...
- http请求中java中的302和sendRedirect的区别
============================================================================================ getCont ...
- php 获取时间今天明天昨天时间戳
<?php echo "今天:".date("Y-m-d")."<br>"; echo "昨天:&qu ...
- Linux 下绑定域名与IP地址
在 Linux 下,hosts 文件的路径是 /etc/hosts,此文件需要有root权限才可编辑,条目也是通过“IP 域名”的格式将域名与IP进行绑定. 对 Linux 的 hosts 配置文件的 ...
- [ActionScript 3.0] AS3 时间日期格式化DateTimeFormatter类的运用
import flash.globalization.DateTimeFormatter; var _timeFormatter:DateTimeFormatter; var _dateFormatt ...
- java异常分类(运行时异常,可检查异常)
NullPointerException:是运行时异常(RuntimeException),也叫非检查异常 所以我们抛出该类异常实例时,方法声明处无需添加throws来列举该类异常的抛出,编译器在编译 ...