/**
  * Generate a Druid query's JSON POST body
  *
  * @param IDruidQueryParameters $params
  *
  * @return string|void
  * @throws Exception
  */
 public function generateQuery(IDruidQueryParameters $params)
 {
     if (!$params instanceof GroupByQueryParameters) {
         throw new Exception('Expected $params to be instanceof GroupByQueryParameters');
     }
     $params->validate();
     $query = $params->getJSONString();
     return $query;
 }
 /**
  * Take parameters and return a valid Druid Query.
  * @param IDruidQueryParameters $params
  *
  * @param TimeBoundaryQueryParameters $params
  * @return string Query payload in JSON
  */
 public function generateQuery(IDruidQueryParameters $params)
 {
     /**
      * @var TimeBoundaryQueryParameters $params
      */
     if (!$params instanceof TimeBoundaryQueryParameters) {
         throw new Exception('Expected $params to be instanceof TimeBoundaryQueryParameters');
     }
     $params->validate();
     $responseObj = array('queryType' => 'timeBoundary', "dataSource" => $params->dataSource);
     $responseString = json_encode($responseObj);
     return $responseString;
 }
 /**
  * Take parameters and return a valid Druid Query.
  * @param IDruidQueryParameters $params
  *
  * @param SegmentMetadataQueryParameters $params
  * @return string Query payload in JSON
  * @throws \DruidFamiliar\Exception\MissingParametersException
  */
 public function generateQuery(IDruidQueryParameters $params)
 {
     /**
      * @var SegmentMetadataQueryParameters $params
      */
     if (!$params instanceof SegmentMetadataQueryParameters) {
         throw new Exception('Expected $params to be instanceof SegmentMetadataQueryParameters');
     }
     $params->validate();
     $responseObj = array('queryType' => 'segmentMetadata', "dataSource" => $params->dataSource, "intervals" => $params->intervals->__toString());
     $responseString = json_encode($responseObj);
     return $responseString;
 }
 public function executeQuery(IDruidQueryGenerator $queryGenerator, IDruidQueryParameters $params, IDruidQueryResponseHandler $responseHandler)
 {
     $params->validate();
     $generatedQuery = $queryGenerator->generateQuery($params);
     // Create a POST request
     $request = $this->createRequest($generatedQuery);
     // Send the request and parse the JSON response into an array
     try {
         $response = $request->send();
     } catch (CurlException $curlException) {
         throw new $curlException();
     }
     $data = $this->parseResponse($response);
     $formattedResponse = $responseHandler->handleResponse($data);
     return $formattedResponse;
 }
 /**
  * Take parameters and return a valid Druid Query.
  * @param IDruidQueryParameters $params
  *
  * @param array $params
  * @return string Druid JSON POST Body
  * @throws \DruidFamiliar\Exception\MissingParametersException
  * @throws \Exception
  */
 public function generateQuery(IDruidQueryParameters $params)
 {
     /**
      * @var SimpleGroupByQueryParameters $params
      */
     if (!$params instanceof SimpleGroupByQueryParameters) {
         throw new Exception('Expected $params to be instanceof SimpleGroupByQueryParameters');
     }
     $params->validate();
     $query = $this->queryTemplate;
     // Assemble the query instead
     $queryKeys = array();
     // We always have these keys
     $queryKeys[] = '"queryType": "{QUERYTYPE}"';
     $queryKeys[] = '"dataSource": "{DATASOURCE}"';
     if (is_array($params->granularity) && count($params->granularity) > 0) {
         $queryKeys[] = '"granularity": {GRANULARITYSPEC.GRAN}';
     } else {
         $queryKeys[] = '"granularity": "{GRANULARITYSPEC.GRAN}"';
     }
     $queryKeys[] = '"dimensions": [ "{NON_TIME_DIMENSIONS}" ]';
     if (count($params->filters) > 0) {
         $queryKeys[] = '"filter": {FILTERS}';
     }
     if (count($params->aggregators) > 0) {
         $queryKeys[] = '"aggregations": [{AGGREGATORS}]';
     }
     if (count($params->postAggregators) > 0) {
         $queryKeys[] = '"postAggregations": [{POSTAGGREGATORS}]';
     }
     $queryKeys[] = '"intervals": ["{INTERVALS}"]';
     $query = "{" . join(",\n", $queryKeys) . "}";
     $query = str_replace('{QUERYTYPE}', $params->queryType, $query);
     $query = str_replace('{DATASOURCE}', $params->dataSource, $query);
     $query = str_replace('{INTERVALS}', $params->intervals, $query);
     if (is_array($params->granularity) && count($params->granularity) > 0) {
         $query = str_replace('{GRANULARITYSPEC.GRAN}', json_encode($params->granularity), $query);
     } else {
         $query = str_replace('{GRANULARITYSPEC.GRAN}', $params->granularity, $query);
     }
     $query = str_replace('{NON_TIME_DIMENSIONS}', join('","', $params->dimensions), $query);
     $query = str_replace('{FILTERS}', join(",", $params->filters), $query);
     $query = str_replace('{AGGREGATORS}', join(",", $params->aggregators), $query);
     $query = str_replace('{POSTAGGREGATORS}', join(",", $params->postAggregators), $query);
     return $query;
 }
 /**
  * @param IndexingTaskStatusQueryParameters $indexTaskParams
  * @return string Query payload in JSON
  */
 public function generateQuery(IDruidQueryParameters $indexTaskParams)
 {
     $indexTaskParams->validate();
     return '';
 }