Marks fork as 2.0.0.
This commit is contained in:
parent
d93a6b5c09
commit
8d8de4a2b0
81 changed files with 1921 additions and 3954 deletions
|
|
@ -1,36 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Expression;
|
||||
|
||||
use Exception;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class KeyFilterExpressionTest extends TestCase
|
||||
{
|
||||
public function testSimpleKeyvalue()
|
||||
{
|
||||
$keyFilter = KeyFilter::setEqualTo('_measurement', 'test_measurement')
|
||||
->andEqualTo('_field', 'user')
|
||||
->or('count', '>=', '1')
|
||||
->and('user', KeyFilter::EQUAL_TO, 'my_username')
|
||||
->orNotEqualTo('test', 'world');
|
||||
final class KeyFilterExpressionTest extends TestCase {
|
||||
public function testSimpleKeyvalue() {
|
||||
$keyFilter = KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
|
||||
->andEqualTo( '_field', 'user' )
|
||||
->or( 'count', '>=', '1' )
|
||||
->and( 'user', KeyFilter::EQUAL_TO, 'my_username' )
|
||||
->orNotEqualTo( 'test', 'world' );
|
||||
|
||||
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
|
||||
$query = 'r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r.count >= "1" and r.user == "my_username" or r.test != "world"';
|
||||
|
||||
$this->assertEquals($keyFilter->__toString(), $query);
|
||||
}
|
||||
$this->assertEquals( $keyFilter->__toString(), $query );
|
||||
}
|
||||
|
||||
public function testInvalidOperator()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
public function testInvalidOperator() {
|
||||
$this->expectException( Exception::class );
|
||||
|
||||
KeyFilter::set('_measurement', '9dkda9e', 'test_measurement')
|
||||
->andEqualTo('_field', 'user')
|
||||
->or('_field', '==', 'field2')
|
||||
->andEqualTo('user', 'my_username');
|
||||
}
|
||||
KeyFilter::set( '_measurement', '9dkda9e', 'test_measurement' )
|
||||
->andEqualTo( '_field', 'user' )
|
||||
->or( '_field', '==', 'field2' )
|
||||
->andEqualTo( 'user', 'my_username' );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,43 +1,40 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
||||
use Hosterra\FluxBuilder\Functions\AggregateWindow;
|
||||
use Hosterra\FluxBuilder\Type\FnType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class AggregateWindowFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleWindow()
|
||||
{
|
||||
$expression = new AggregateWindow('20s', 'mean');
|
||||
final class AggregateWindowFunctionTest extends TestCase {
|
||||
public function testSimpleWindow() {
|
||||
$expression = new AggregateWindow( '20s', 'mean' );
|
||||
|
||||
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
||||
$query = '|> aggregateWindow(every: 20s, fn: mean) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testAllParameters()
|
||||
{
|
||||
$expression = new AggregateWindow(
|
||||
'20s',
|
||||
FnType::params(['r'])->withBody('r._field == "test"'),
|
||||
[
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'column' => '_value',
|
||||
'timeSrc' => '_stop',
|
||||
'timeDst' => '_time',
|
||||
'createEmpty' => false
|
||||
]
|
||||
);
|
||||
public function testAllParameters() {
|
||||
$expression = new AggregateWindow(
|
||||
'20s',
|
||||
FnType::params( [ 'r' ] )->withBody( 'r._field == "test"' ),
|
||||
[
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'column' => '_value',
|
||||
'timeSrc' => '_stop',
|
||||
'timeDst' => '_time',
|
||||
'createEmpty' => false
|
||||
]
|
||||
);
|
||||
|
||||
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
|
||||
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
|
||||
$query = '|> aggregateWindow(every: 20s, period: every, offset: 0s, fn: (r) => r._field == "test", ' .
|
||||
'location: "location", ' . 'column: "_value", timeSrc: "_stop", timeDst: "_time", createEmpty: false) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
||||
use Hosterra\FluxBuilder\Functions\Count;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CountFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleCount()
|
||||
{
|
||||
$expression = new Count();
|
||||
final class CountFunctionTest extends TestCase {
|
||||
public function testSimpleCount() {
|
||||
$expression = new Count();
|
||||
|
||||
$query = '|> count() ';
|
||||
$query = '|> count() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testCountWithColumn()
|
||||
{
|
||||
$expression = new Count('_value');
|
||||
public function testCountWithColumn() {
|
||||
$expression = new Count( '_value' );
|
||||
|
||||
$query = '|> count(column: "_value") ';
|
||||
$query = '|> count(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||
use Hosterra\FluxBuilder\Functions\Duplicate;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class DuplicateFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleDuplicate()
|
||||
{
|
||||
$expression = new Duplicate('tag', 'tag_dup');
|
||||
final class DuplicateFunctionTest extends TestCase {
|
||||
public function testSimpleDuplicate() {
|
||||
$expression = new Duplicate( 'tag', 'tag_dup' );
|
||||
|
||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||
$query = '|> duplicate(column: "tag", as: "tag_dup") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,48 +1,33 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Filter;
|
||||
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
use Hosterra\FluxBuilder\Functions\Filter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FilterFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleFilter()
|
||||
{
|
||||
$expression = new Filter(KeyValue::setEqualTo('_measurement', 'test_measurement')
|
||||
->andEqualTo('_field', 'user')
|
||||
->orEqualTo('_field', 'field2')
|
||||
->andEqualTo('user', 'my_username'));
|
||||
final class FilterFunctionTest extends TestCase {
|
||||
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
public function testFieldFilter() {
|
||||
$expression = new Filter( [ 'user', 'field2', 'field3' ] );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
||||
|
||||
public function testFieldFilter()
|
||||
{
|
||||
$expression = new Filter(['user', 'field2', 'field3']);
|
||||
$this->assertEquals( $expression->__toString(), $query );
|
||||
}
|
||||
|
||||
$query = '|> filter(fn: (r) => r._field == "user" or r._field == "field2" or r._field == "field3") ';
|
||||
public function testKeyFilter() {
|
||||
$expression = new Filter( KeyFilter::setEqualTo( '_measurement', 'test_measurement' )
|
||||
->andEqualTo( '_field', 'user' )
|
||||
->orEqualTo( '_field', 'field2' )
|
||||
->andEqualTo( 'user', 'my_username' ) );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
|
||||
public function testKeyFilter()
|
||||
{
|
||||
$expression = new Filter(KeyFilter::setEqualTo('_measurement', 'test_measurement')
|
||||
->andEqualTo('_field', 'user')
|
||||
->orEqualTo('_field', 'field2')
|
||||
->andEqualTo('user', 'my_username'));
|
||||
|
||||
$query = '|> filter(fn: (r) => r._measurement == "test_measurement" and r._field == "user" or ' .
|
||||
'r._field == "field2" and r.user == "my_username") ';
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$this->assertEquals( $expression->__toString(), $query );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
||||
use Hosterra\FluxBuilder\Functions\First;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FirstFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleFirst()
|
||||
{
|
||||
$expression = new First();
|
||||
final class FirstFunctionTest extends TestCase {
|
||||
public function testSimpleFirst() {
|
||||
$expression = new First();
|
||||
|
||||
$query = '|> first() ';
|
||||
$query = '|> first() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testFirstWithColumn()
|
||||
{
|
||||
$expression = new First('something');
|
||||
public function testFirstWithColumn() {
|
||||
$expression = new First( 'something' );
|
||||
|
||||
$query = '|> first(column: "something") ';
|
||||
$query = '|> first(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,40 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\From;
|
||||
use Hosterra\FluxBuilder\Functions\From;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FromFunctionTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider somethingProvider
|
||||
*/
|
||||
public function testSomething($settings, $query)
|
||||
{
|
||||
$expression = new From($settings);
|
||||
final class FromFunctionTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider somethingProvider
|
||||
*/
|
||||
public function testSomething( $settings, $query ) {
|
||||
$expression = new From( $settings );
|
||||
|
||||
$this->assertEquals($expression->__toString(), $query);
|
||||
}
|
||||
$this->assertEquals( $expression->__toString(), $query );
|
||||
}
|
||||
|
||||
public function somethingProvider(): array
|
||||
{
|
||||
return [
|
||||
'from bucket' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
],
|
||||
'from(bucket: "test-bucket") '
|
||||
],
|
||||
'from bucket and host' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
'host' => 'test',
|
||||
],
|
||||
'from(bucket: "test-bucket", host: "test") '
|
||||
],
|
||||
];
|
||||
}
|
||||
public function somethingProvider(): array {
|
||||
return [
|
||||
'from bucket' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
],
|
||||
'from(bucket: "test-bucket") '
|
||||
],
|
||||
'from bucket and host' => [
|
||||
[
|
||||
'bucket' => 'test-bucket',
|
||||
'host' => 'test',
|
||||
],
|
||||
'from(bucket: "test-bucket", host: "test") '
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Group;
|
||||
use Hosterra\FluxBuilder\Functions\Group;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class GroupFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleGroup()
|
||||
{
|
||||
$expression = new Group(['foo', 'bar'], 'by');
|
||||
final class GroupFunctionTest extends TestCase {
|
||||
public function testSimpleGroup() {
|
||||
$expression = new Group( [ 'foo', 'bar' ], 'by' );
|
||||
|
||||
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
||||
$query = '|> group(columns: ["foo", "bar"], mode: "by") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Last;
|
||||
use Hosterra\FluxBuilder\Functions\Last;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LastFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleLast()
|
||||
{
|
||||
$expression = new Last();
|
||||
final class LastFunctionTest extends TestCase {
|
||||
public function testSimpleLast() {
|
||||
$expression = new Last();
|
||||
|
||||
$query = '|> last(column: "_value") ';
|
||||
$query = '|> last(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testLastWithValue()
|
||||
{
|
||||
$expression = new Last('something');
|
||||
public function testLastWithValue() {
|
||||
$expression = new Last( 'something' );
|
||||
|
||||
$query = '|> last(column: "something") ';
|
||||
$query = '|> last(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Limit;
|
||||
use Hosterra\FluxBuilder\Functions\Limit;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class LimitFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleLimit()
|
||||
{
|
||||
$expression = new Limit(1);
|
||||
final class LimitFunctionTest extends TestCase {
|
||||
public function testSimpleLimit() {
|
||||
$expression = new Limit( 1 );
|
||||
|
||||
$query = '|> limit(n: 1, offset: 0) ';
|
||||
$query = '|> limit(n: 1, offset: 0) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testLimitWithOffset()
|
||||
{
|
||||
$expression = new Limit(10, 2);
|
||||
public function testLimitWithOffset() {
|
||||
$expression = new Limit( 10, 2 );
|
||||
|
||||
$query = '|> limit(n: 10, offset: 2) ';
|
||||
$query = '|> limit(n: 10, offset: 2) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Map;
|
||||
use Arendsen\FluxQueryBuilder\Expression\Map as MapExpression;
|
||||
use Arendsen\FluxQueryBuilder\Expression\Selection as SelectionExpression;
|
||||
use Hosterra\FluxBuilder\Functions\Map;
|
||||
use Hosterra\FluxBuilder\Expression\Map as MapExpression;
|
||||
use Hosterra\FluxBuilder\Expression\Selection as SelectionExpression;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MapFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMap()
|
||||
{
|
||||
$expression = new Map('r with name: r.user');
|
||||
final class MapFunctionTest extends TestCase {
|
||||
public function testSimpleMap() {
|
||||
$expression = new Map( 'r with name: r.user' );
|
||||
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithMapObject()
|
||||
{
|
||||
$expression = new Map(MapExpression::with('name', 'r.user'));
|
||||
public function testWithMapObject() {
|
||||
$expression = new Map( MapExpression::with( 'name', 'r.user' ) );
|
||||
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
$query = '|> map(fn: (r) => ({ r with name: r.user })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testRecordMapObject()
|
||||
{
|
||||
$expression = new Map(MapExpression::columns([
|
||||
'time' => 'r._time',
|
||||
'source' => 'r.tag',
|
||||
'alert' => SelectionExpression::if('r._value > 10')->then(true)->else(false)->__toString(),
|
||||
'test' => SelectionExpression::if('r._value > 10')->then('yes')->else('no')->__toString()
|
||||
])->__toString());
|
||||
public function testRecordMapObject() {
|
||||
$expression = new Map( MapExpression::columns( [
|
||||
'time' => 'r._time',
|
||||
'source' => 'r.tag',
|
||||
'alert' => SelectionExpression::if( 'r._value > 10' )->then( true )->else( false )->__toString(),
|
||||
'test' => SelectionExpression::if( 'r._value > 10' )->then( 'yes' )->else( 'no' )->__toString()
|
||||
] )->__toString() );
|
||||
|
||||
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
||||
'alert: if r._value > 10 then true else false, ' .
|
||||
'test: if r._value > 10 then "yes" else "no"} })) ';
|
||||
$query = '|> map(fn: (r) => ({ {time: r._time, source: r.tag, ' .
|
||||
'alert: if r._value > 10 then true else false, ' .
|
||||
'test: if r._value > 10 then "yes" else "no"} })) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Max;
|
||||
use Hosterra\FluxBuilder\Functions\Max;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MaxFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMax()
|
||||
{
|
||||
$expression = new Max();
|
||||
final class MaxFunctionTest extends TestCase {
|
||||
public function testSimpleMax() {
|
||||
$expression = new Max();
|
||||
|
||||
$query = '|> max() ';
|
||||
$query = '|> max() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testMaxWithColumn()
|
||||
{
|
||||
$expression = new Max('something');
|
||||
public function testMaxWithColumn() {
|
||||
$expression = new Max( 'something' );
|
||||
|
||||
$query = '|> max(column: "something") ';
|
||||
$query = '|> max(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Mean;
|
||||
use Hosterra\FluxBuilder\Functions\Mean;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MeanFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMean()
|
||||
{
|
||||
$expression = new Mean();
|
||||
final class MeanFunctionTest extends TestCase {
|
||||
public function testSimpleMean() {
|
||||
$expression = new Mean();
|
||||
|
||||
$query = '|> mean() ';
|
||||
$query = '|> mean() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithParameterColumn()
|
||||
{
|
||||
$expression = new Mean('test');
|
||||
public function testWithParameterColumn() {
|
||||
$expression = new Mean( 'test' );
|
||||
|
||||
$query = '|> mean(column: "test") ';
|
||||
$query = '|> mean(column: "test") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Min;
|
||||
use Hosterra\FluxBuilder\Functions\Min;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class MinFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleMin()
|
||||
{
|
||||
$expression = new Min();
|
||||
final class MinFunctionTest extends TestCase {
|
||||
public function testSimpleMin() {
|
||||
$expression = new Min();
|
||||
|
||||
$query = '|> min() ';
|
||||
$query = '|> min() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testMinWithColumn()
|
||||
{
|
||||
$expression = new Min('something');
|
||||
public function testMinWithColumn() {
|
||||
$expression = new Min( 'something' );
|
||||
|
||||
$query = '|> min(column: "something") ';
|
||||
$query = '|> min(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,47 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use DateTime;
|
||||
use Arendsen\FluxQueryBuilder\Functions\Range;
|
||||
use Hosterra\FluxBuilder\Functions\Range;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class RangeFunctionTest extends TestCase
|
||||
{
|
||||
public function testOnlyStartOption()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 18:00:00')
|
||||
);
|
||||
final class RangeFunctionTest extends TestCase {
|
||||
public function testOnlyStartOption() {
|
||||
$expression = new Range(
|
||||
new DateTime( '2022-08-12 18:00:00' )
|
||||
);
|
||||
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z)) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testWithStopOption()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 18:00:00'),
|
||||
new DateTime('2022-08-12 20:00:00')
|
||||
);
|
||||
public function testWithStopOption() {
|
||||
$expression = new Range(
|
||||
new DateTime( '2022-08-12 18:00:00' ),
|
||||
new DateTime( '2022-08-12 20:00:00' )
|
||||
);
|
||||
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
||||
$query = '|> range(start: time(v: 2022-08-12T18:00:00Z), stop: time(v: 2022-08-12T20:00:00Z)) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testRangeInBetween()
|
||||
{
|
||||
$expression = new Range(
|
||||
new DateTime('2022-08-12 17:31:00'),
|
||||
new DateTime('2022-08-12 18:31:00')
|
||||
);
|
||||
public function testRangeInBetween() {
|
||||
$expression = new Range(
|
||||
new DateTime( '2022-08-12 17:31:00' ),
|
||||
new DateTime( '2022-08-12 18:31:00' )
|
||||
);
|
||||
|
||||
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
|
||||
$expected = '|> range(start: time(v: 2022-08-12T17:31:00Z), stop: time(v: 2022-08-12T18:31:00Z)) ';
|
||||
|
||||
$this->assertEquals($expected, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $expected, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Reduce;
|
||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
||||
use Hosterra\FluxBuilder\Functions\Reduce;
|
||||
use Hosterra\FluxBuilder\Type\MathType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ReduceFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleReduce()
|
||||
{
|
||||
$expression = new Reduce(['sum' => new MathType('r._value + accumulator.sum')], ['sum' => 0]);
|
||||
final class ReduceFunctionTest extends TestCase {
|
||||
public function testSimpleReduce() {
|
||||
$expression = new Reduce( [ 'sum' => new MathType( 'r._value + accumulator.sum' ) ], [ 'sum' => 0 ] );
|
||||
|
||||
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
||||
$query = '|> reduce(fn: (r, accumulator) => ({sum: r._value + accumulator.sum}), identity: {sum: 0}) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sort;
|
||||
use Hosterra\FluxBuilder\Functions\Sort;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SortFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleSort()
|
||||
{
|
||||
$expression = new Sort(['foo', 'bar'], true);
|
||||
final class SortFunctionTest extends TestCase {
|
||||
public function testSimpleSort() {
|
||||
$expression = new Sort( [ 'foo', 'bar' ], true );
|
||||
|
||||
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
||||
$query = '|> sort(columns: ["foo", "bar"], desc: true) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,18 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Sum;
|
||||
use Hosterra\FluxBuilder\Functions\Sum;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class SumFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleSum()
|
||||
{
|
||||
$expression = new Sum('_value');
|
||||
final class SumFunctionTest extends TestCase {
|
||||
public function testSimpleSum() {
|
||||
$expression = new Sum( '_value' );
|
||||
|
||||
$query = '|> sum(column: "_value") ';
|
||||
$query = '|> sum(column: "_value") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,29 +1,26 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Unique;
|
||||
use Hosterra\FluxBuilder\Functions\Unique;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class UniqueunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleUnique()
|
||||
{
|
||||
$expression = new Unique();
|
||||
final class UniqueunctionTest extends TestCase {
|
||||
public function testSimpleUnique() {
|
||||
$expression = new Unique();
|
||||
|
||||
$query = '|> unique() ';
|
||||
$query = '|> unique() ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testUniqueWithColumn()
|
||||
{
|
||||
$expression = new Unique('something');
|
||||
public function testUniqueWithColumn() {
|
||||
$expression = new Unique( 'something' );
|
||||
|
||||
$query = '|> unique(column: "something") ';
|
||||
$query = '|> unique(column: "something") ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,38 +1,35 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Functions\Window;
|
||||
use Hosterra\FluxBuilder\Functions\Window;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class WindowFunctionTest extends TestCase
|
||||
{
|
||||
public function testSimpleWindow()
|
||||
{
|
||||
$expression = new Window('20s');
|
||||
final class WindowFunctionTest extends TestCase {
|
||||
public function testSimpleWindow() {
|
||||
$expression = new Window( '20s' );
|
||||
|
||||
$query = '|> window(every: 20s) ';
|
||||
$query = '|> window(every: 20s) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
|
||||
public function testAllParameters()
|
||||
{
|
||||
$expression = new Window('20s', [
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'timeColumn' => '_time',
|
||||
'startColumn' => '_start',
|
||||
'stopColumn' => '_stop',
|
||||
'createEmpty' => true
|
||||
]);
|
||||
public function testAllParameters() {
|
||||
$expression = new Window( '20s', [
|
||||
'period' => 'every',
|
||||
'offset' => '0s',
|
||||
'location' => 'location',
|
||||
'timeColumn' => '_time',
|
||||
'startColumn' => '_start',
|
||||
'stopColumn' => '_stop',
|
||||
'createEmpty' => true
|
||||
] );
|
||||
|
||||
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||
|
||||
$this->assertEquals($query, $expression->__toString());
|
||||
}
|
||||
$this->assertEquals( $query, $expression->__toString() );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,256 +1,253 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use Closure;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyFilter;
|
||||
use Arendsen\FluxQueryBuilder\Expression\KeyValue;
|
||||
use Hosterra\FluxBuilder\Expression\KeyFilter;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Arendsen\FluxQueryBuilder\QueryBuilder;
|
||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
||||
use Hosterra\FluxBuilder\QueryBuilder;
|
||||
use Hosterra\FluxBuilder\Type\MathType;
|
||||
|
||||
final class QueryBuilderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider newTestsProvider
|
||||
*/
|
||||
public function testBasicQuery(string $methodName, array $params = [], string $expected = '')
|
||||
{
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket('test_bucket')
|
||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
|
||||
->fromMeasurement('test_measurement');
|
||||
final class QueryBuilderTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider newTestsProvider
|
||||
*/
|
||||
public function testBasicQuery( string $methodName, array $params = [], string $expected = '' ) {
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket( 'test_bucket' )
|
||||
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
|
||||
->fromMeasurement( 'test_measurement' );
|
||||
|
||||
call_user_func_array([$queryBuilder, $methodName], $params);
|
||||
call_user_func_array( [ $queryBuilder, $methodName ], $params );
|
||||
|
||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
|
||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: time(v: 2022-08-12T17:31:00Z)) ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' . $expected;
|
||||
|
||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
||||
}
|
||||
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
|
||||
}
|
||||
|
||||
public function newTestsProvider(): array
|
||||
{
|
||||
return [
|
||||
'addAggregateWindow' => [
|
||||
'addAggregateWindow',
|
||||
['20s', 'mean', ['timeDst' => '_time']],
|
||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||
],
|
||||
'addBottom' => [
|
||||
'addBottom',
|
||||
[2, ['_value']],
|
||||
'|> bottom(n: 2, columns: ["_value"]) '
|
||||
],
|
||||
'addCount' => [
|
||||
'addCount',
|
||||
['_value'],
|
||||
'|> count(column: "_value") '
|
||||
],
|
||||
'addDuplicate' => [
|
||||
'addDuplicate',
|
||||
['old_name', 'new_name'],
|
||||
'|> duplicate(column: "old_name", as: "new_name") '
|
||||
],
|
||||
'addFilter' => [
|
||||
'addFilter',
|
||||
[KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3)],
|
||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
|
||||
],
|
||||
'addKeyFilter' => [
|
||||
'addKeyFilter',
|
||||
[KeyFilter::setEqualTo('user', 'username')],
|
||||
'|> filter(fn: (r) => r.user == "username") '
|
||||
],
|
||||
'addFieldFilter' => [
|
||||
'addFieldFilter',
|
||||
[['email', 'username']],
|
||||
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
|
||||
],
|
||||
'addFirst' => [
|
||||
'addFirst',
|
||||
['something'],
|
||||
'|> first(column: "something") '
|
||||
],
|
||||
'addGroup' => [
|
||||
'addGroup',
|
||||
[['_field', 'ip']],
|
||||
'|> group(columns: ["_field", "ip"], mode: "by") '
|
||||
],
|
||||
'addLast' => [
|
||||
'addLast',
|
||||
['something'],
|
||||
'|> last(column: "something") '
|
||||
],
|
||||
'addLimit' => [
|
||||
'addLimit',
|
||||
[20, 40],
|
||||
'|> limit(n: 20, offset: 40) '
|
||||
],
|
||||
'addMap' => [
|
||||
'addMap',
|
||||
['r with name: r.user'],
|
||||
'|> map(fn: (r) => ({ r with name: r.user })) '
|
||||
],
|
||||
'addMax' => [
|
||||
'addMax',
|
||||
[],
|
||||
'|> max() '
|
||||
],
|
||||
'addMean' => [
|
||||
'addMean',
|
||||
['something'],
|
||||
'|> mean(column: "something") '
|
||||
],
|
||||
'addMin' => [
|
||||
'addMin',
|
||||
['something'],
|
||||
'|> min(column: "something") '
|
||||
],
|
||||
'addRawFunction' => [
|
||||
'addRawFunction',
|
||||
['|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")'],
|
||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||
],
|
||||
'addReduce' => [
|
||||
'addReduce',
|
||||
[['count' => new MathType('accumulator.count + 1')], ['count' => 0]],
|
||||
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
|
||||
],
|
||||
'addSort' => [
|
||||
'addSort',
|
||||
[['column1', 'column2'], true],
|
||||
'|> sort(columns: ["column1", "column2"], desc: true) '
|
||||
],
|
||||
'addSum' => [
|
||||
'addSum',
|
||||
['something'],
|
||||
'|> sum(column: "something") '
|
||||
],
|
||||
'addUnique' => [
|
||||
'addUnique',
|
||||
['something'],
|
||||
'|> unique(column: "something") '
|
||||
],
|
||||
'addUnwindow' => [
|
||||
'addUnwindow',
|
||||
[],
|
||||
'|> window(every: inf) '
|
||||
],
|
||||
'addWindow' => [
|
||||
'addWindow',
|
||||
['20s', ['timeColumn' => '_time']],
|
||||
'|> window(every: 20s, timeColumn: "_time") '
|
||||
],
|
||||
];
|
||||
}
|
||||
public function newTestsProvider(): array {
|
||||
return [
|
||||
'addAggregateWindow' => [
|
||||
'addAggregateWindow',
|
||||
[ '20s', 'mean', [ 'timeDst' => '_time' ] ],
|
||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||
],
|
||||
'addBottom' => [
|
||||
'addBottom',
|
||||
[ 2, [ '_value' ] ],
|
||||
'|> bottom(n: 2, columns: ["_value"]) '
|
||||
],
|
||||
'addCount' => [
|
||||
'addCount',
|
||||
[ '_value' ],
|
||||
'|> count(column: "_value") '
|
||||
],
|
||||
'addDuplicate' => [
|
||||
'addDuplicate',
|
||||
[ 'old_name', 'new_name' ],
|
||||
'|> duplicate(column: "old_name", as: "new_name") '
|
||||
],
|
||||
'addFilter' => [
|
||||
'addFilter',
|
||||
[ KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) ],
|
||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) '
|
||||
],
|
||||
'addKeyFilter' => [
|
||||
'addKeyFilter',
|
||||
[ KeyFilter::setEqualTo( 'user', 'username' ) ],
|
||||
'|> filter(fn: (r) => r.user == "username") '
|
||||
],
|
||||
'addFieldFilter' => [
|
||||
'addFieldFilter',
|
||||
[ [ 'email', 'username' ] ],
|
||||
'|> filter(fn: (r) => r._field == "email" or r._field == "username") '
|
||||
],
|
||||
'addFirst' => [
|
||||
'addFirst',
|
||||
[ 'something' ],
|
||||
'|> first(column: "something") '
|
||||
],
|
||||
'addGroup' => [
|
||||
'addGroup',
|
||||
[ [ '_field', 'ip' ] ],
|
||||
'|> group(columns: ["_field", "ip"], mode: "by") '
|
||||
],
|
||||
'addLast' => [
|
||||
'addLast',
|
||||
[ 'something' ],
|
||||
'|> last(column: "something") '
|
||||
],
|
||||
'addLimit' => [
|
||||
'addLimit',
|
||||
[ 20, 40 ],
|
||||
'|> limit(n: 20, offset: 40) '
|
||||
],
|
||||
'addMap' => [
|
||||
'addMap',
|
||||
[ 'r with name: r.user' ],
|
||||
'|> map(fn: (r) => ({ r with name: r.user })) '
|
||||
],
|
||||
'addMax' => [
|
||||
'addMax',
|
||||
[],
|
||||
'|> max() '
|
||||
],
|
||||
'addMean' => [
|
||||
'addMean',
|
||||
[ 'something' ],
|
||||
'|> mean(column: "something") '
|
||||
],
|
||||
'addMin' => [
|
||||
'addMin',
|
||||
[ 'something' ],
|
||||
'|> min(column: "something") '
|
||||
],
|
||||
'addRawFunction' => [
|
||||
'addRawFunction',
|
||||
[ '|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time")' ],
|
||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||
],
|
||||
'addReduce' => [
|
||||
'addReduce',
|
||||
[ [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] ],
|
||||
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) '
|
||||
],
|
||||
'addSort' => [
|
||||
'addSort',
|
||||
[ [ 'column1', 'column2' ], true ],
|
||||
'|> sort(columns: ["column1", "column2"], desc: true) '
|
||||
],
|
||||
'addSum' => [
|
||||
'addSum',
|
||||
[ 'something' ],
|
||||
'|> sum(column: "something") '
|
||||
],
|
||||
'addUnique' => [
|
||||
'addUnique',
|
||||
[ 'something' ],
|
||||
'|> unique(column: "something") '
|
||||
],
|
||||
'addUnwindow' => [
|
||||
'addUnwindow',
|
||||
[],
|
||||
'|> window(every: inf) '
|
||||
],
|
||||
'addWindow' => [
|
||||
'addWindow',
|
||||
[ '20s', [ 'timeColumn' => '_time' ] ],
|
||||
'|> window(every: 20s, timeColumn: "_time") '
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider throwsExceptionWithoutRequiredDataProvider
|
||||
*/
|
||||
public function testThrowsExceptionWithoutRequiredData($from, $measurement, $range)
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
/**
|
||||
* @dataProvider throwsExceptionWithoutRequiredDataProvider
|
||||
*/
|
||||
public function testThrowsExceptionWithoutRequiredData( $from, $measurement, $range ) {
|
||||
$this->expectException( Exception::class );
|
||||
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder = new QueryBuilder();
|
||||
|
||||
if ($from) {
|
||||
$queryBuilder->from($from);
|
||||
}
|
||||
if ($range) {
|
||||
$queryBuilder->addRangeStart($range['start']);
|
||||
}
|
||||
if ($measurement) {
|
||||
$queryBuilder->fromMeasurement($measurement);
|
||||
}
|
||||
if ( $from ) {
|
||||
$queryBuilder->from( $from );
|
||||
}
|
||||
if ( $range ) {
|
||||
$queryBuilder->addRangeStart( $range['start'] );
|
||||
}
|
||||
if ( $measurement ) {
|
||||
$queryBuilder->fromMeasurement( $measurement );
|
||||
}
|
||||
|
||||
$queryBuilder->build();
|
||||
}
|
||||
$queryBuilder->build();
|
||||
}
|
||||
|
||||
public function throwsExceptionWithoutRequiredDataProvider(): array
|
||||
{
|
||||
return [
|
||||
'without from data' => [
|
||||
null, 'test_measurement', ['start' => new DateTime('2022-08-12 20:05:00')],
|
||||
],
|
||||
'without measurement data' => [
|
||||
['from' => 'test_bucket'], null, ['start' => new DateTime('2022-08-12 20:05:00')],
|
||||
],
|
||||
'without range data' => [
|
||||
['from' => 'test_bucket'], 'test_measurement', null,
|
||||
],
|
||||
];
|
||||
}
|
||||
public function throwsExceptionWithoutRequiredDataProvider(): array {
|
||||
return [
|
||||
'without from data' => [
|
||||
null,
|
||||
'test_measurement',
|
||||
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
|
||||
],
|
||||
'without measurement data' => [
|
||||
[ 'from' => 'test_bucket' ],
|
||||
null,
|
||||
[ 'start' => new DateTime( '2022-08-12 20:05:00' ) ],
|
||||
],
|
||||
'without range data' => [
|
||||
[ 'from' => 'test_bucket' ],
|
||||
'test_measurement',
|
||||
null,
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function testThrowsExceptionWhenIncorrectOrder()
|
||||
{
|
||||
$this->expectException(Exception::class);
|
||||
public function testThrowsExceptionWhenIncorrectOrder() {
|
||||
$this->expectException( Exception::class );
|
||||
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->from(['bucket' => 'test_bucket'])
|
||||
->fromMeasurement('test_measurement')
|
||||
->addRangeStart(new DateTime('2022-08-12 20:05:00'));
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->from( [ 'bucket' => 'test_bucket' ] )
|
||||
->fromMeasurement( 'test_measurement' )
|
||||
->addRangeStart( new DateTime( '2022-08-12 20:05:00' ) );
|
||||
|
||||
$queryBuilder->build();
|
||||
}
|
||||
$queryBuilder->build();
|
||||
}
|
||||
|
||||
public function testQueryWithWindow()
|
||||
{
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket('test_bucket')
|
||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'))
|
||||
->addReduce(['count' => new MathType('accumulator.count + 1')], ['count' => 0])
|
||||
->addWindow('20s')
|
||||
->addMean()
|
||||
->addDuplicate('tag', 'tag_dup')
|
||||
->fromMeasurement('test_measurement')
|
||||
->addFilter(KeyValue::setGreaterOrEqualTo('count', 2)->andGreaterOrEqualTo('count2', 3))
|
||||
->addKeyFilter(KeyFilter::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2))
|
||||
->addUnWindow();
|
||||
public function testQueryWithWindow() {
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket( 'test_bucket' )
|
||||
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) )
|
||||
->addReduce( [ 'count' => new MathType( 'accumulator.count + 1' ) ], [ 'count' => 0 ] )
|
||||
->addWindow( '20s' )
|
||||
->addMean()
|
||||
->addDuplicate( 'tag', 'tag_dup' )
|
||||
->fromMeasurement( 'test_measurement' )
|
||||
->addFilter( KeyValue::setGreaterOrEqualTo( 'count', 2 )->andGreaterOrEqualTo( 'count2', 3 ) )
|
||||
->addKeyFilter( KeyFilter::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() |> duplicate(column: "tag", as: "tag_dup") ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
|
||||
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
|
||||
$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() |> duplicate(column: "tag", as: "tag_dup") ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'|> filter(fn: (r) => r.count >= 2 and r.count2 >= 3) ' .
|
||||
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> window(every: inf) ';
|
||||
|
||||
$this->assertEquals($expectedQuery, $queryBuilder->build());
|
||||
}
|
||||
$this->assertEquals( $expectedQuery, $queryBuilder->build() );
|
||||
}
|
||||
|
||||
public function testCorrectInstancesAreCreated()
|
||||
{
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket('test_bucket')
|
||||
->addRangeStart(new DateTime('2022-08-12 17:31:00'));
|
||||
public function testCorrectInstancesAreCreated() {
|
||||
$queryBuilder = new QueryBuilder();
|
||||
$queryBuilder->fromBucket( 'test_bucket' )
|
||||
->addRangeStart( new DateTime( '2022-08-12 17:31:00' ) );
|
||||
|
||||
$instances = [
|
||||
\Arendsen\FluxQueryBuilder\Functions\From::class,
|
||||
\Arendsen\FluxQueryBuilder\Functions\Range::class,
|
||||
\Arendsen\FluxQueryBuilder\Functions\Measurement::class,
|
||||
];
|
||||
$instances = [
|
||||
\Hosterra\FluxBuilder\Functions\From::class,
|
||||
\Hosterra\FluxBuilder\Functions\Range::class,
|
||||
\Hosterra\FluxBuilder\Functions\Measurement::class,
|
||||
];
|
||||
|
||||
$requiredFluxQueryParts = $this->getClassProperty($queryBuilder, 'requiredFluxQueryParts');
|
||||
$requiredFluxQueryParts = $this->getClassProperty( $queryBuilder, 'requiredFluxQueryParts' );
|
||||
|
||||
foreach ($requiredFluxQueryParts as $keyPart => $part) {
|
||||
$this->assertEquals($instances[$keyPart], $part);
|
||||
}
|
||||
}
|
||||
foreach ( $requiredFluxQueryParts as $keyPart => $part ) {
|
||||
$this->assertEquals( $instances[ $keyPart ], $part );
|
||||
}
|
||||
}
|
||||
|
||||
private function getClassProperty($object, string $property): array
|
||||
{
|
||||
$propertyReader = function & ($object, $property) {
|
||||
$value = & Closure::bind(function & () use ($property) {
|
||||
return $this->$property;
|
||||
}, $object, $object)->__invoke();
|
||||
private function getClassProperty( $object, string $property ): array {
|
||||
$propertyReader = function & ( $object, $property ) {
|
||||
$value = &Closure::bind( function & () use ( $property ) {
|
||||
return $this->$property;
|
||||
}, $object, $object )->__invoke();
|
||||
|
||||
return $value;
|
||||
};
|
||||
return $value;
|
||||
};
|
||||
|
||||
return $propertyReader($object, $property);
|
||||
}
|
||||
return $propertyReader( $object, $property );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,97 +1,94 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
declare( strict_types=1 );
|
||||
|
||||
namespace Tests\Type;
|
||||
|
||||
use DateTime;
|
||||
use Arendsen\FluxQueryBuilder\Type;
|
||||
use Arendsen\FluxQueryBuilder\Type\CustomType;
|
||||
use Arendsen\FluxQueryBuilder\Type\DurationType;
|
||||
use Arendsen\FluxQueryBuilder\Type\FnType;
|
||||
use Arendsen\FluxQueryBuilder\Type\MathType;
|
||||
use Arendsen\FluxQueryBuilder\Type\RecordType;
|
||||
use Hosterra\FluxBuilder\Type;
|
||||
use Hosterra\FluxBuilder\Type\CustomType;
|
||||
use Hosterra\FluxBuilder\Type\DurationType;
|
||||
use Hosterra\FluxBuilder\Type\FnType;
|
||||
use Hosterra\FluxBuilder\Type\MathType;
|
||||
use Hosterra\FluxBuilder\Type\RecordType;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class FactoryTypeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getFluxStringProvider
|
||||
*/
|
||||
public function testGetFluxString($value, $expected)
|
||||
{
|
||||
$type = new Type($value);
|
||||
final class FactoryTypeTest extends TestCase {
|
||||
/**
|
||||
* @dataProvider getFluxStringProvider
|
||||
*/
|
||||
public function testGetFluxString( $value, $expected ) {
|
||||
$type = new Type( $value );
|
||||
|
||||
$this->assertEquals($expected, $type->__toString());
|
||||
}
|
||||
$this->assertEquals( $expected, $type->__toString() );
|
||||
}
|
||||
|
||||
public function getFluxStringProvider()
|
||||
{
|
||||
return [
|
||||
'DateTime' => [
|
||||
new DateTime('2022-08-15 23:09:00'),
|
||||
'time(v: 2022-08-15T23:09:00Z)',
|
||||
],
|
||||
'String' => [
|
||||
'value',
|
||||
'"value"',
|
||||
],
|
||||
'Integer' => [
|
||||
12345,
|
||||
'12345'
|
||||
],
|
||||
'Boolean True' => [
|
||||
true,
|
||||
'true'
|
||||
],
|
||||
'Boolean False' => [
|
||||
false,
|
||||
'false'
|
||||
],
|
||||
'Array' => [
|
||||
['hello', 'world'],
|
||||
'"hello", "world"'
|
||||
],
|
||||
'Dictionary' => [
|
||||
['hello' => 'world', 'foo' => 'bar'],
|
||||
'hello: "world", foo: "bar"'
|
||||
],
|
||||
'Array Multidimensional' => [
|
||||
['hello' => ['test', 'foo']],
|
||||
'hello: ["test", "foo"]'
|
||||
],
|
||||
'Array Multidimensional 2' => [
|
||||
['hello' => ['test' => 'bar', 'foo' => 'hi']],
|
||||
'hello: [test: "bar", foo: "hi"]'
|
||||
],
|
||||
'RecordType' => [
|
||||
new RecordType(['foo' => 'bar', 'nested' => ['hello' => 'world']]),
|
||||
'{foo: "bar", nested: {hello: "world"}}'
|
||||
],
|
||||
'DurationType' => [
|
||||
new DurationType('5h'),
|
||||
'5h',
|
||||
],
|
||||
'MathType' => [
|
||||
new MathType('r.count + 1'),
|
||||
'r.count + 1'
|
||||
],
|
||||
'CustomType' => [
|
||||
new CustomType('this can be anything'),
|
||||
'this can be anything'
|
||||
],
|
||||
'FnType with only content' => [
|
||||
FnType::params([])->withBlock('r with _value: r._value * r._value'),
|
||||
'() => { r with _value: r._value * r._value }'
|
||||
],
|
||||
'FnType with params and a body' => [
|
||||
FnType::params(['r'])->withBody('r with _value: r._value * r._value'),
|
||||
'(r) => r with _value: r._value * r._value'
|
||||
],
|
||||
'FnType with params and a block' => [
|
||||
FnType::params(['r', 'a'])->withBlock('return r with _value: r._value * r._value'),
|
||||
'(r, a) => { return r with _value: r._value * r._value }'
|
||||
],
|
||||
];
|
||||
}
|
||||
public function getFluxStringProvider() {
|
||||
return [
|
||||
'DateTime' => [
|
||||
new DateTime( '2022-08-15 23:09:00' ),
|
||||
'time(v: 2022-08-15T23:09:00Z)',
|
||||
],
|
||||
'String' => [
|
||||
'value',
|
||||
'"value"',
|
||||
],
|
||||
'Integer' => [
|
||||
12345,
|
||||
'12345'
|
||||
],
|
||||
'Boolean True' => [
|
||||
true,
|
||||
'true'
|
||||
],
|
||||
'Boolean False' => [
|
||||
false,
|
||||
'false'
|
||||
],
|
||||
'Array' => [
|
||||
[ 'hello', 'world' ],
|
||||
'"hello", "world"'
|
||||
],
|
||||
'Dictionary' => [
|
||||
[ 'hello' => 'world', 'foo' => 'bar' ],
|
||||
'hello: "world", foo: "bar"'
|
||||
],
|
||||
'Array Multidimensional' => [
|
||||
[ 'hello' => [ 'test', 'foo' ] ],
|
||||
'hello: ["test", "foo"]'
|
||||
],
|
||||
'Array Multidimensional 2' => [
|
||||
[ 'hello' => [ 'test' => 'bar', 'foo' => 'hi' ] ],
|
||||
'hello: [test: "bar", foo: "hi"]'
|
||||
],
|
||||
'RecordType' => [
|
||||
new RecordType( [ 'foo' => 'bar', 'nested' => [ 'hello' => 'world' ] ] ),
|
||||
'{foo: "bar", nested: {hello: "world"}}'
|
||||
],
|
||||
'DurationType' => [
|
||||
new DurationType( '5h' ),
|
||||
'5h',
|
||||
],
|
||||
'MathType' => [
|
||||
new MathType( 'r.count + 1' ),
|
||||
'r.count + 1'
|
||||
],
|
||||
'CustomType' => [
|
||||
new CustomType( 'this can be anything' ),
|
||||
'this can be anything'
|
||||
],
|
||||
'FnType with only content' => [
|
||||
FnType::params( [] )->withBlock( 'r with _value: r._value * r._value' ),
|
||||
'() => { r with _value: r._value * r._value }'
|
||||
],
|
||||
'FnType with params and a body' => [
|
||||
FnType::params( [ 'r' ] )->withBody( 'r with _value: r._value * r._value' ),
|
||||
'(r) => r with _value: r._value * r._value'
|
||||
],
|
||||
'FnType with params and a block' => [
|
||||
FnType::params( [ 'r', 'a' ] )->withBlock( 'return r with _value: r._value * r._value' ),
|
||||
'(r, a) => { return r with _value: r._value * r._value }'
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue