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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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