Move Exceptions in a separate directory + Fixed Range function
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
79edee7400
commit
648709bd19
9 changed files with 47 additions and 19 deletions
7
src/Exception/ExpressionNotImplementedException.php
Normal file
7
src/Exception/ExpressionNotImplementedException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ExpressionNotImplementedException extends Exception {}
|
||||
7
src/Exception/FunctionNotImplementedException.php
Normal file
7
src/Exception/FunctionNotImplementedException.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionNotImplementedException extends Exception {}
|
||||
14
src/Exception/FunctionRequiredSettingMissingException.php
Normal file
14
src/Exception/FunctionRequiredSettingMissingException.php
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Exception;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionRequiredSettingMissingException extends Exception {
|
||||
|
||||
public function __construct(string $functionName, string $message)
|
||||
{
|
||||
parent::__construct('Function ' . $functionName . ' - ' . $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Exception\ExpressionNotImplementedException;
|
||||
|
||||
abstract class Base {
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Expression;
|
||||
|
||||
use Exception;
|
||||
|
||||
class ExpressionNotImplementedException extends Exception {}
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
use Arendsen\FluxQueryBuilder\Function\FunctionNotImplementedException;
|
||||
|
||||
abstract class Base {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class FunctionNotImplementedException extends Exception {}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||
|
||||
use Arendsen\FluxQueryBuilder\Formatters;
|
||||
use Arendsen\FluxQueryBuilder\Exception\FunctionRequiredSettingMissingException;
|
||||
|
||||
class Range extends Base {
|
||||
|
||||
|
|
@ -18,7 +18,18 @@ class Range extends Base {
|
|||
|
||||
public function __toString()
|
||||
{
|
||||
return '|> range(' . Formatters::toFluxArrayString($this->settings) . ') ';
|
||||
if(!isset($this->settings['start']))
|
||||
{
|
||||
throw new FunctionRequiredSettingMissingException('Range', 'Start setting is required!');
|
||||
}
|
||||
|
||||
$settingsString = 'start: ' . $this->settings['start'];
|
||||
if(isset($this->settings['stop']))
|
||||
{
|
||||
$settingsString .= ', stop: ' . $this->settings['stop'];
|
||||
}
|
||||
|
||||
return '|> range(' . $settingsString . ') ';
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -35,7 +35,7 @@ final class QueryBuilderTest extends TestCase {
|
|||
'test_measurement',
|
||||
'-360h',
|
||||
null,
|
||||
'from(bucket: "example_bucket") |> range(start: "-360h") |> filter(fn: (r) => r._measurement == "test_measurement") '
|
||||
'from(bucket: "example_bucket") |> range(start: -360h) |> filter(fn: (r) => r._measurement == "test_measurement") '
|
||||
],
|
||||
'query with filter' => [
|
||||
[
|
||||
|
|
@ -44,7 +44,7 @@ final class QueryBuilderTest extends TestCase {
|
|||
'test_measurement',
|
||||
'-360h',
|
||||
KeyValue::setEqualTo('user', 'username'),
|
||||
'from(bucket: "example_bucket") |> range(start: "-360h") |> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'from(bucket: "example_bucket") |> range(start: -360h) |> filter(fn: (r) => r._measurement == "test_measurement") ' .
|
||||
'|> filter(fn: (r) => r.user == "username") '
|
||||
],
|
||||
];
|
||||
|
|
@ -99,7 +99,7 @@ final class QueryBuilderTest extends TestCase {
|
|||
->addReduce(['count' => 'accumulator.count + 1'], ['count' => 0])
|
||||
->addFilter(KeyValue::setGreaterOrEqualTo('count', 1)->andGreaterOrEqualTo('count2', 2));
|
||||
|
||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: "-3h") ' .
|
||||
$expectedQuery = 'from(bucket: "test_bucket") |> range(start: -3h) ' .
|
||||
'|> reduce(fn: (r, accumulator) => ({count: accumulator.count + 1}), identity: {count: 0}) ' .
|
||||
'|> filter(fn: (r) => r._measurement == "test_measurement") |> filter(fn: (r) => r._field == "username") ' .
|
||||
'|> filter(fn: (r) => r.count >= 1 and r.count2 >= 2) |> map(fn: (r) => ({ r with name: r.user })) ' .
|
||||
|
|
|
|||
Loading…
Add table
editor.link_modal.header
Reference in a new issue