Change optional parameters of window() into an array
Signed-off-by: davidarendsen <davidarendsen@hey.com>
This commit is contained in:
parent
5951c9b8b1
commit
156d771b24
3 changed files with 24 additions and 68 deletions
|
|
@ -14,71 +14,27 @@ class Window extends Base
|
||||||
private $every;
|
private $every;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var string|null $period
|
* @var array $options
|
||||||
*/
|
*/
|
||||||
private $period;
|
private $options;
|
||||||
|
|
||||||
/**
|
public function __construct($every, array $options = []) {
|
||||||
* @var string|null $offset
|
|
||||||
*/
|
|
||||||
private $offset;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null $location
|
|
||||||
*/
|
|
||||||
private $location;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null $timeColumn
|
|
||||||
*/
|
|
||||||
private $timeColumn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null $startColumn
|
|
||||||
*/
|
|
||||||
private $startColumn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null $stopColumn
|
|
||||||
*/
|
|
||||||
private $stopColumn;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool $createEmpty
|
|
||||||
*/
|
|
||||||
private $createEmpty;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
$every,
|
|
||||||
?string $period = null,
|
|
||||||
?string $offset = null,
|
|
||||||
?string $location = null,
|
|
||||||
?string $timeColumn = null,
|
|
||||||
?string $startColumn = null,
|
|
||||||
?string $stopColumn = null,
|
|
||||||
bool $createEmpty = false
|
|
||||||
) {
|
|
||||||
$this->every = $every;
|
$this->every = $every;
|
||||||
$this->period = $period;
|
$this->options = $options;
|
||||||
$this->offset = $offset;
|
|
||||||
$this->location = $location;
|
|
||||||
$this->timeColumn = $timeColumn;
|
|
||||||
$this->startColumn = $startColumn;
|
|
||||||
$this->stopColumn = $stopColumn;
|
|
||||||
$this->createEmpty = $createEmpty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
$input = new ArrayType(array_filter([
|
$input = new ArrayType(array_filter([
|
||||||
'every' => new DurationType($this->every),
|
'every' => new DurationType($this->every),
|
||||||
'period' => $this->period ? new DurationType($this->period) : null,
|
'period' => isset($this->options['period']) ? new DurationType($this->options['period']) : null,
|
||||||
'offset' => $this->offset ? new DurationType($this->offset) : null,
|
'offset' => isset($this->options['offset']) ? new DurationType($this->options['offset']) : null,
|
||||||
'location' => $this->location ? new Type($this->location) : null,
|
'location' => isset($this->options['location']) ? new Type($this->options['location']) : null,
|
||||||
'timeColumn' => $this->timeColumn ? new Type($this->timeColumn) : null,
|
'timeColumn' => isset($this->options['timeColumn']) ? new Type($this->options['timeColumn']) : null,
|
||||||
'startColumn' => $this->startColumn ? new Type($this->startColumn) : null,
|
'startColumn' => isset($this->options['startColumn']) ? new Type($this->options['startColumn']) : null,
|
||||||
'stopColumn' => $this->stopColumn ? new Type($this->stopColumn) : null,
|
'stopColumn' => isset($this->options['stopColumn']) ? new Type($this->options['stopColumn']) : null,
|
||||||
'createEmpty' => $this->createEmpty ? new Type($this->createEmpty) : null,
|
'createEmpty' => isset($this->options['createEmpty']) && $this->options['createEmpty'] ?
|
||||||
|
new Type($this->options['createEmpty']) : null,
|
||||||
]));
|
]));
|
||||||
return '|> window(' . $input . ') ';
|
return '|> window(' . $input . ') ';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -175,19 +175,11 @@ class QueryBuilder
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addWindow(
|
public function addWindow($every, array $options = []): QueryBuilder
|
||||||
$every,
|
{
|
||||||
?string $period = null,
|
|
||||||
?string $offset = null,
|
|
||||||
?string $location = null,
|
|
||||||
?string $timeColumn = null,
|
|
||||||
?string $startColumn = null,
|
|
||||||
?string $stopColumn = null,
|
|
||||||
bool $createEmpty = false
|
|
||||||
): QueryBuilder {
|
|
||||||
$this->addToQueryArray(
|
$this->addToQueryArray(
|
||||||
self::FLUX_PART_WINDOW,
|
self::FLUX_PART_WINDOW,
|
||||||
new Window($every, $period, $offset, $location, $timeColumn, $startColumn, $stopColumn, $createEmpty)
|
new Window($every, $options)
|
||||||
);
|
);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,15 @@ final class WindowFunctionTest extends TestCase
|
||||||
|
|
||||||
public function testAllParameters()
|
public function testAllParameters()
|
||||||
{
|
{
|
||||||
$expression = new Window('20s', 'every', '0s', 'location', '_time', '_start', '_stop', true);
|
$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", ' .
|
$query = '|> window(every: 20s, period: every, offset: 0s, location: "location", ' .
|
||||||
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
'timeColumn: "_time", startColumn: "_start", stopColumn: "_stop", createEmpty: true) ';
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue