Add duplicate() function to Query Builder
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
f2b3871b21
commit
2cca3daa17
4 changed files with 72 additions and 3 deletions
20
tests/Functions/DuplicateFunctionTest.php
Normal file
20
tests/Functions/DuplicateFunctionTest.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class DuplicateFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleDuplicate()
|
||||
{
|
||||
$expression = new Duplicate('tag', 'tag_dup');
|
||||
|
||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
}
|
||||
|
|
@ -124,12 +124,14 @@ final class QueryBuilderTest extends TestCase
|
|||
->addWindow('20s')
|
||||
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
|
||||
->addMean()
|
||||
->addDuplicate('tag', 'tag_dup')
|
||||
->addFilter(KeyValue::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2))
|
||||
->addUnWindow();
|
||||
|
||||
$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) |> mean() |> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'|> window(every: 20s) |> mean() |> duplicate(column: "tag", as: "tag_dup") ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
|
||||
|
||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue