Add addBottom function
Signed-off-by: David Arendsen <darendsen@gamepoint.com>
This commit is contained in:
parent
483e67a2e8
commit
9e2bde4217
5 changed files with 91 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ On this page you will find the methods you can use in the query builder.
|
||||||
or [fromBucket()](functions/fromBucket.md)
|
or [fromBucket()](functions/fromBucket.md)
|
||||||
* [fromMeasurement()](functions/fromMeasurement.md)
|
* [fromMeasurement()](functions/fromMeasurement.md)
|
||||||
* [addAggregateWindow()](functions/addAggregateWindow.md)
|
* [addAggregateWindow()](functions/addAggregateWindow.md)
|
||||||
|
* [addBottom()](functions/addBottom.md)
|
||||||
* [addCount()](functions/addCount.md)
|
* [addCount()](functions/addCount.md)
|
||||||
* [addDuplicate()](functions/addDuplicate.md)
|
* [addDuplicate()](functions/addDuplicate.md)
|
||||||
* [addFieldFilter()](functions/addFieldFilter.md)
|
* [addFieldFilter()](functions/addFieldFilter.md)
|
||||||
|
|
|
||||||
45
docs/functions/addBottom.md
Normal file
45
docs/functions/addBottom.md
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
# Flux Query Builder Docs
|
||||||
|
|
||||||
|
## Functions » addBottom()
|
||||||
|
|
||||||
|
### Parameters:
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<th>Name</th>
|
||||||
|
<th>Required</th>
|
||||||
|
<th>Data type</th>
|
||||||
|
<th>Description</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>n</td>
|
||||||
|
<td>Yes</td>
|
||||||
|
<td>string</td>
|
||||||
|
<td>Number of rows to return from each input table.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>columns</td>
|
||||||
|
<td>No</td>
|
||||||
|
<td>array</td>
|
||||||
|
<td>List of columns to sort by. Default is ["_value"].</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
|
||||||
|
### Example
|
||||||
|
|
||||||
|
```php
|
||||||
|
->addBottom(2, ['_value'])
|
||||||
|
```
|
||||||
|
|
||||||
|
This will result in the following Flux function part:
|
||||||
|
|
||||||
|
```
|
||||||
|
|> bottom(n: 2, columns: ["_value"])
|
||||||
|
```
|
||||||
|
|
||||||
|
### Extra resources
|
||||||
|
|
||||||
|
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/bottom/)
|
||||||
|
|
@ -4,6 +4,7 @@ namespace Arendsen\FluxQueryBuilder\Builder;
|
||||||
|
|
||||||
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
use Arendsen\FluxQueryBuilder\Builder\QueryBuilderInterface;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
use Arendsen\FluxQueryBuilder\Functions\AggregateWindow;
|
||||||
|
use Arendsen\FluxQueryBuilder\Functions\Bottom;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Count;
|
use Arendsen\FluxQueryBuilder\Functions\Count;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
use Arendsen\FluxQueryBuilder\Functions\Duplicate;
|
||||||
use Arendsen\FluxQueryBuilder\Functions\First;
|
use Arendsen\FluxQueryBuilder\Functions\First;
|
||||||
|
|
@ -30,6 +31,12 @@ trait Universe
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addBottom(int $n, array $columns = []): QueryBuilderInterface
|
||||||
|
{
|
||||||
|
$this->addToQuery(new Bottom($n, $columns));
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function addCount(?string $column = null): QueryBuilderInterface
|
public function addCount(?string $column = null): QueryBuilderInterface
|
||||||
{
|
{
|
||||||
$this->addToQuery(
|
$this->addToQuery(
|
||||||
|
|
|
||||||
33
src/Functions/Bottom.php
Normal file
33
src/Functions/Bottom.php
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Arendsen\FluxQueryBuilder\Functions;
|
||||||
|
|
||||||
|
use Arendsen\FluxQueryBuilder\Type\ArrayType;
|
||||||
|
|
||||||
|
class Bottom extends Base
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var int $n
|
||||||
|
*/
|
||||||
|
private $n;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array $columns
|
||||||
|
*/
|
||||||
|
private $columns;
|
||||||
|
|
||||||
|
public function __construct($n, array $columns = [])
|
||||||
|
{
|
||||||
|
$this->n = $n;
|
||||||
|
$this->columns = $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
$input = new ArrayType(array_filter([
|
||||||
|
'n' => $this->n,
|
||||||
|
'columns' => $this->columns ?: null,
|
||||||
|
]));
|
||||||
|
return '|> bottom(' . $input . ') ';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -41,6 +41,11 @@ final class QueryBuilderTest extends TestCase
|
||||||
['20s', 'mean', ['timeDst' => '_time']],
|
['20s', 'mean', ['timeDst' => '_time']],
|
||||||
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
'|> aggregateWindow(every: 20s, fn: mean, timeDst: "_time") '
|
||||||
],
|
],
|
||||||
|
'addBottom' => [
|
||||||
|
'addBottom',
|
||||||
|
[2, ['_value']],
|
||||||
|
'|> bottom(n: 2, columns: ["_value"]) '
|
||||||
|
],
|
||||||
'addCount' => [
|
'addCount' => [
|
||||||
'addCount',
|
'addCount',
|
||||||
['_value'],
|
['_value'],
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue