Add documentation about addMap, addSort, addUnwindow, and addWindow

Signed-off-by: David Arendsen <darendsen@gamepoint.com>
This commit is contained in:
David Arendsen 2023-02-11 17:33:35 +01:00
commit b7e0b21c8f
9 changed files with 179 additions and 27 deletions

View file

@ -11,13 +11,17 @@ or [fromBucket()](functions/fromBucket.md)
* [addDuplicate()](functions/addDuplicate.md)
* [addFieldFilter()](functions/addFieldFilter.md)
* [addGroup()](functions/addGroup.md)
* [addLast()](functions/addLast.md)
* [addLimit()](functions/addLimit.md)
* [addMap()](functions/addMap.md)
* [addMean()](functions/addMean.md)
* [addRangeStart()](functions/addRangeStart.md)
or [addRangeInBetween()](functions/addRangeInBetween.md)
* [addReduce()](functions/addReduce.md)
* [addSort()](functions/addSort.md)
* [addSum()](functions/addSum.md)
* [addLast()](functions/addLast.md)
* [addUnwindow()](functions/addUnwindow.md)
* [addWindow()](functions/addWindow.md)
Anything missing here? You can use this method to add anything to the query:
* [addRawFunction()](functions/addRawFunction.md)

View file

@ -0,0 +1,39 @@
# Flux Query Builder Docs
## Functions &raquo; addMap()
### Parameters:
<table>
<tbody>
<tr>
<th>Name</th>
<th>Required</th>
<th>Data type</th>
<th>Description</th>
</tr>
<tr>
<td>fn</td>
<td>Yes</td>
<td>string</td>
<td>Single argument function to apply to each record. The return value must be a record.</td>
</tr>
</tbody>
</table>
### Example
```php
->addMap('r with name: r.user')
```
This will result in the following Flux function part:
```
|> map(fn: (r) => ({ r with name: r.user }))
```
### Extra resources
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/map/)

View file

@ -0,0 +1,39 @@
# Flux Query Builder Docs
## Functions &raquo; addSort()
### Parameters:
<table>
<tbody>
<tr>
<th>Name</th>
<th>Required</th>
<th>Data type</th>
<th>Description</th>
</tr>
<tr>
<td>columns</td>
<td>Yes</td>
<td>array</td>
<td>List of columns to sort by. Default is ["_value"].</td>
</tr>
</tbody>
</table>
### Example
```php
->addSort(['column1', 'column2'], true)
```
This will result in the following Flux function part:
```
|> sort(columns: ["column1", "column2"], desc: true)
```
### Extra resources
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/sort/)

View file

@ -0,0 +1,21 @@
# Flux Query Builder Docs
## Functions &raquo; addUnwindow()
Keeping aggregate values in separate tables generally isnt the format in which you want your data. Use the window() function to “unwindow” your data into a single infinite (inf) window.
### Example
```php
->addUnwindow()
```
This will result in the following Flux function part:
```
|> window(every: inf)
```
### Extra resources
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/window/)

View file

@ -0,0 +1,71 @@
# Flux Query Builder Docs
## Functions &raquo; addWindow()
### Parameters:
<table>
<tbody>
<tr>
<th>Name</th>
<th>Required</th>
<th>Data type</th>
<th>Description</th>
</tr>
<tr>
<td>every</td>
<td>Yes</td>
<td>string</td>
<td>Duration of time between windows.</td>
</tr>
<tr>
<td>options</td>
<td>No</td>
<td>array</td>
<td>
<ul>
<li>
period (string): <i>Duration of windows. Default is the 'every' value.</i>
</li>
<li>
offset (string): <i>Duration to shift the window boundaries by. Default is '0s'.</i>
</li>
<li>
location (string): <i>Location used to determine timezone. Default is the 'location' option.</i>
</li>
<li>
timeColumn (string): <i>Column that contains time values. Default is '_time'.</i>
</li>
<li>
startColumn (string): <i>Column to store the window start time in. Default is '_start'.</i>
</li>
<li>
stopColumn (string): <i>Column to store the window stop time in. Default is '_stop'.</i>
</li>
<li>
createEmpty (boolean): <i>Create empty tables for empty window. Default is false.</i>
</li>
</ul>
</td>
</tr>
</tbody>
</table>
### Example
```php
->addWindow('20s', [
'timeColumn' => '_time',
])
```
This will result in the following Flux function part:
```
|> window(every: 20s, timeColumn: "_time")
```
### Extra resources
* [Flux documentation](https://docs.influxdata.com/flux/v0.x/stdlib/universe/window/)

View file

@ -1,22 +0,0 @@
<?php
namespace Arendsen\FluxQueryBuilder\Builder;
class FluxPart
{
public const FROM = 'from';
public const MEASUREMENT = 'measurement';
public const RANGE = 'range';
public const FILTERS = 'filters';
public const REDUCE = 'reduce';
public const MAP = 'map';
public const SORT = 'sort';
public const GROUP = 'group';
public const LIMIT = 'limit';
public const WINDOW = 'window';
public const MEAN = 'mean';
public const DUPLICATE = 'duplicate';
public const UNWINDOW = 'unwindow';
public const AGGREGATEWINDOW = 'aggregateWindow';
public const RAWFUNCTION = 'raw';
}

View file

@ -25,7 +25,7 @@ trait Universe
return $this;
}
public function addSort(array $columns, $desc): QueryBuilderInterface
public function addSort(array $columns = ['_value'], bool $desc = false): QueryBuilderInterface
{
$this->addToQuery(
new Sort($columns, $desc)

View file

@ -16,7 +16,7 @@ class Sort extends Base
*/
private $desc;
public function __construct(array $columns, bool $desc = false)
public function __construct(array $columns = ['_value'], bool $desc = false)
{
$this->columns = $columns;
$this->desc = $desc;

View file

@ -113,8 +113,8 @@ final class QueryBuilderTest extends TestCase
],
'addWindow' => [
'addWindow',
['20s'],
'|> window(every: 20s) '
['20s', ['timeColumn' => '_time']],
'|> window(every: 20s, timeColumn: "_time") '
],
];
}