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

      

  • 相关阅读:
    客户主数据批导
    update module (更新模块)
    关于SAP的编码范围
    MV45AOZZ 销售订单增强点
    BAPI list
    sap crm 常用表
    ME01 创建货源清单
    SAP采购寄售业务操作步骤
    让APK 成功在 Windows 运行并可以设置本地文件
    FastAdmin 学习线路 (2018-06-09 更新)
  • 原文地址:https://www.cnblogs.com/zlingh/p/4399708.html
Copyright © 2011-2022 走看看