当前位置: 首页 > 工具软件 > PHP-Druid > 使用案例 >

php通过druid请求数据

太叔景曜
2023-12-01

此博文主要是博主做的笔记,不做过多表述

public function getPvstart($params){

         $query['queryType'] = 'groupBy';   //请求类型

         $query['granularity'] = 'day';         //粒度,时间分段(all,none,hour,day,week,month,quarter,years)

         $query['dataSource'] = "tianmu_swan_core_indicators_search_feed_d_d";            //数据源(表)

         $fields = [];

         $base_query = [

             $this->filterValue('appKey',$params['appKey']), 

             $this->filterValue('source','all'),

         ];

         $query['filter'] = [           //过滤条件

             'type'  => 'and',

             'fields'=> array_merge($fields,$base_query),

         ];

         $query['aggregations'] = [      //聚合--分组求和的字段

             [

                 'type'     => 'longSum',

                 'name'     => 'pv',

                 'fieldName'=> 'total_launch_pv',

             ],

         ];

         $query['intervals'] = [$params['startTime'] . '/' . $params['endTime']];    //间隔,时间起始

         $item['url'] = $this->druid->getRealBroker();           //请求的主机

         $item['data'] = json_encode($query);

         $query_data[] = $item;

         $res = $this->druid->send($query_data);

         return $res[0]['event'];

     }

 private function filterValue($key,$value){    //封装的过滤条件

         return [

             'type'      => 'selector',

             'dimension' => $key,

             'value'     => $value,

         ];

     }

 类似资料: