Improve WindowFucnctionTest
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
156d771b24
commit
ff3c757543
3 changed files with 10 additions and 10 deletions
|
|
@ -18,7 +18,8 @@ class Window extends Base
|
||||||
*/
|
*/
|
||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
public function __construct($every, array $options = []) {
|
public function __construct($every, array $options = [])
|
||||||
|
{
|
||||||
$this->every = $every;
|
$this->every = $every;
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
@ -33,7 +34,7 @@ class Window extends Base
|
||||||
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
|
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
|
||||||
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
|
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
|
||||||
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : 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,
|
new Type($this->options['createEmpty']) : null,
|
||||||
]));
|
]));
|
||||||
return '|> window(' . $input . ') ';
|
return '|> window(' . $input . ') ';
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@ final class WindowFunctionTest extends TestCase
|
||||||
public function testAllParameters()
|
public function testAllParameters()
|
||||||
{
|
{
|
||||||
$expression = new Window('20s', [
|
$expression = new Window('20s', [
|
||||||
'period' => 'every',
|
'period' => 'every',
|
||||||
'offset' => '0s',
|
'offset' => '0s',
|
||||||
'location' => 'location',
|
'location' => 'location',
|
||||||
'timeColumn' => '_time',
|
'timeColumn' => '_time',
|
||||||
'startColumn' => '_start',
|
'startColumn' => '_start',
|
||||||
'stopColumn' => '_stop',
|
'stopColumn' => '_stop',
|
||||||
'createEmpty' => true
|
'createEmpty' => true
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -103,20 +103,19 @@ final class QueryBuilderTest extends TestCase
|
||||||
->addFieldFilter(['username', 'ip'])
|
->addFieldFilter(['username', 'ip'])
|
||||||
->addMap('r with name: r.user')
|
->addMap('r with name: r.user')
|
||||||
->addGroup(['_field', 'ip'])
|
->addGroup(['_field', 'ip'])
|
||||||
->addWindow('20s')
|
|
||||||
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
|
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
|
||||||
->addFilter(KeyValue::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2));
|
->addFilter(KeyValue::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2));
|
||||||
|
|
||||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
$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}) ' .
|
'|> 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) ' .
|
'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") ';
|
'|> map(fn: (r) => ({ r with name: r.user })) |> group(columns: ["_field", "ip"], mode: "by") ';
|
||||||
|
|
||||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueryWithUnWindow()
|
public function testQueryWithWindow()
|
||||||
{
|
{
|
||||||
$queryBuilder = new QueryBuilder();
|
$queryBuilder = new QueryBuilder();
|
||||||
$queryBuilder->fromBucket('test_bucket')
|
$queryBuilder->fromBucket('test_bucket')
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue