• 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);
    

      

  • 相关阅读:
    Redis系列一
    浅谈Java开发三层架构
    plsql乱码问题
    eclipse工作空间的常用设置
    《经典面试系列》- 索引
    《数据库优化》- 存储过程
    遍历Map的四种方式(Java)
    调用微信js sdk
    根据多个成对的cron表达式生成的时间段,合并
    关于Map集合注意事项
  • 原文地址:https://www.cnblogs.com/zlingh/p/4399708.html
Copyright © 2020-2023  润新知