Change optional parameters of aggregateWindow into an array

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-09-01 12:30:10 +00:00
commit 5951c9b8b1
4 changed files with 31 additions and 70 deletions

View file

@ -11,7 +11,7 @@ final class AggregateWindowFunctionTest extends TestCase
{
public function testSimpleWindow()
{
$expression = new AggregateWindow('20s', null, null, 'mean');
$expression = new AggregateWindow('20s', 'mean');
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
@ -20,7 +20,15 @@ final class AggregateWindowFunctionTest extends TestCase
public function testAllParameters()
{
$expression = new AggregateWindow('20s', 'every', '0s', 'mean', 'location', '_value', '_stop', '_time', false);
$expression = new AggregateWindow('20s', 'mean', [
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'column' => '_value',
'timeSrc' => '_stop',
'timeDst' => '_time',
'createEmpty' => false
]);
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: mean, location: "location", ' .
'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';

View file

@ -141,12 +141,13 @@ final class QueryBuilderTest extends TestCase
$queryBuilder->fromBucket('test_bucket')
->fromMeasurement('test_measurement')
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
->addAggregateWindow('20s', null, null, 'mean')
->addAggregateWindow('20s', 'mean', ['timeDst' => '_time'])
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0]);
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") |> aggregateWindow(every: 20s, fn: mean) ';
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") ';
$this->assertEquals($expectedQuery, $queryBuilder->build());
}