Improve WindowFucnctionTest

Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
davidarendsen 2022-09-01 12:57:36 +00:00
commit ff3c757543
3 changed files with 10 additions and 10 deletions

View file

@ -18,7 +18,8 @@ class Window extends Base
*/
private $options;
public function __construct($every, array $options = []) {
public function __construct($every, array $options = [])
{
$this->every = $every;
$this->options = $options;
}
@ -33,7 +34,7 @@ class Window extends Base
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : null,
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
new Type($this->options['createEmpty']) : null,
]));
return '|> window(' . $input . ') ';

View file

@ -21,12 +21,12 @@ final class WindowFunctionTest extends TestCase
public function testAllParameters()
{
$expression = new Window('20s', [
'period' => 'every',
'period' => 'every',
'offset' => '0s',
'location' => 'location',
'timeColumn' => '_time',
'startColumn' => '_start',
'stopColumn' => '_stop',
'location' => 'location',
'timeColumn' => '_time',
'startColumn' => '_start',
'stopColumn' => '_stop',
'createEmpty' => true
]);

View file

@ -103,20 +103,19 @@ final class QueryBuilderTest extends TestCase
->addFieldFilter(['username', 'ip'])
->addMap('r with name: r.user')
->addGroup(['_field', 'ip'])
->addWindow('20s')
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
->addFilter(KeyValue::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2));
$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}) ' .
'|> window(every: 20s) |> filter(fn: (r) => r._measurement == "test_measurement") |> filter(fn: (r) => ' .
'|> filter(fn: (r) => r._measurement == "test_measurement") |> filter(fn: (r) => ' .
'r._field == "username" or r._field == "ip") |> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) ' .
'|> map(fn: (r) => ({ r with name: r.user })) |> group(columns: ["_field", "ip"], mode: "by") ';
$this->assertEquals($expectedQuery, $queryBuilder->build());
}
public function testQueryWithUnWindow()
public function testQueryWithWindow()
{
$queryBuilder = new QueryBuilder();
$queryBuilder->fromBucket('test_bucket')