public function testBasic() { $connection = new Druid(new Driver(), ['proxy' => 'tcp://127.0.0.1:8080']); $queries = new GroupByQueryBuilder(); $queries->setDataSource('kpi_registrations_v1'); $queries->setGranularity('P1D', 'UTC'); $queries->addInterval(new \DateTime('2000-01-01'), new \DateTime()); $queries->addAggregator($queries->aggregator()->count('count_rows')); $queries->addAggregator($queries->aggregator()->doubleSum('sum_rows', 'event_count_metric')); $queries->addAggregator($queries->aggregator()->hyperUnique('registrations', 'registrations')); $queries->addDimension('project', 'project'); $queries->addPostAggregator($queries->postAggregator()->arithmeticPostAggregator('average', '/', [$queries->postAggregator()->fieldAccessPostAggregator('sum_rows', 'sum_rows'), $queries->postAggregator()->fieldAccessPostAggregator('count_rows', 'count_rows')])); $response = $connection->send($queries->getQuery()); $this->assertInstanceOf(ResponseInterface::class, $response); }
public function testSettersAndGetters() { $builder = new GroupByQueryBuilder(); $now = new \DateTime(); $builder->setDataSource('dataSource')->setGranularity(new PeriodGranularity('P1D', 'UTC'))->setFilter($builder->filter()->selectorFilter('gender', 'male'))->addInterval($now, new \DateTime())->addAggregator($builder->aggregator()->doubleSum('sum', 'sum'))->addAggregator($builder->aggregator()->count('count'))->addDimension('gender', 'gender')->addPostAggregator($builder->postAggregator()->arithmeticPostAggregator('average', '/', [$builder->postAggregator()->fieldAccessPostAggregator('sum', 'sum'), $builder->postAggregator()->fieldAccessPostAggregator('count', 'count')]))->setHaving($builder->having()->equalToHaving('gender', 300)); $query = $builder->getQuery(); $this->assertEquals('dataSource', $query->getDataSource()->getName()); $this->assertEquals('gender', $query->getFilter()->getDimension()); $this->assertEquals('male', $query->getFilter()->getValue()); $this->assertEquals($now->format('Y-m-d\\TH:i:s+0000'), $query->getIntervals()[0]->getStart()); $this->assertEquals('sum', $query->getAggregations()[0]->getName()); $this->assertEquals('count', $query->getAggregations()[1]->getName()); $this->assertEquals('gender', $query->getDimensions()[0]->getDimension()); $this->assertEquals('average', $query->getPostAggregations()[0]->getName()); $this->assertEquals(300, $query->getHaving()->getValue()); }