zoukankan      html  css  js  c++  java
  • 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("
    ",$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);
    

      

  • 相关阅读:
    bzoj 3779 重组病毒——LCT维护子树信息
    bzoj 4010 [HNOI2015]菜肴制作——贪心
    bzoj 2535 && bzoj 2109 [Noi2010]Plane 航空管制——贪心
    bzoj 3671 [Noi2014]随机数生成器——贪心(时间复杂度分配)
    bzoj 2395 [Balkan 2011]Timeismoney——最小乘积生成树
    bzoj 3157 && bzoj 3516 国王奇遇记——推式子
    bzoj 1101 [POI2007]Zap——反演
    hdu 4372 Count the Buildings——第一类斯特林数
    bzoj 2406 矩阵——有源汇上下界可行流
    bzoj 2039 [2009国家集训队]employ人员雇佣——二元关系
  • 原文地址:https://www.cnblogs.com/zlingh/p/4399708.html
Copyright © 2011-2022 走看看