Flux restructure (#3141)

* initial changes for flux restructure

* added all aliases

* added introduced date to all flux functions

* marked linearBins and logarithmicBins as draft

* migrated flux stdlib to new flux section, added version range to article template

* fixed list-all-functions shortcode

* duplicated and reordered flux spec, added page-nav shortcode, closes #1870

* added filtering functionality to list-all-functions shortcode

* added function tags

* Stdlib reorg (#2130)

* consolidated influxdb packages

* stdlib rename and reorg

* reorg existing contrib docs

* added keep-url to http.get example

* reorg built-in directory, add function types docs

* updated links

* updated all related links

* fixed reference links in influxdb docs

* updated all internal flux links

* updated flux links in influxdb

* one last link update

* restyle product dropdown

* update flux links in influxdb 1.7 and 1.8

* fixed shortcode call

* updated task options in flux options doc

* Flux 'interpolate' package (#2148)

* add interpolate package, closes #1649

* added missing page description to interpolate package doc

* removed unnecessary space from interpolate description

* updated interpolate package description

* ported from() note to new flux section

* New list filter javascript (#2185)

* generalized list filtering for telegraf plugins and flux functions

* added flux tags, updated filter list functionality

* added more flux tags

* added new experimental functions

* updated derivative params

* ported over new experimental functions

* fixed bad copy-pasta

* ported new notification endpoints into new flux docs

* updated flux function categories

* ported flux changes from master

* fixed product dropdown

* fixed regexp.findString example

* ported flux 0.109 changes

* updated array package aliases and supported version

* ported new functions into flux dir

* added aliases to interpolate package

* ported flux v0.114 packages

* added enterpise logic to url selector modal

* fix minor typo

* Update Flux param type convention (#2515)

* fix minor typo

* WIP new flux data type convention

* wip more param type updates

* cleaned up function type specs

* ported flux 0.115.0 packages and functions

* ported tickscript package

* ported today function

* added aliases to tickscript pkg

* updated timedMovingAverage params example

* updated to function with remote creds

* port flux 0.118 changes over

* port flux changes into flux-restructure

* ported changes from flux 0.123.0 and updated flux function docs

* updated contrib package summary

* updated function definition of schema.tagValues

* ported recent flux changes to the restructure branch

* port changes from master

* Flux get started (#3036)

* Flux group keys demo (#2553)

* interactive group key example

* added js and shortcode for group key demo

* updated group key demo to address PR feedback

* shortened sample data set

* Flux get started intro and data model (#2619)

* starting flux intro content, resolved merge conflicts

* WIP flux get started docs

* WIP flux get started

* flux get started intro and data model

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Update content/flux/v0.x/get-started/data-model.md

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* addressed PR feedback in flux get started

* updated flux docs landing page

* more updates to flux landing page

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Flux query basics (#2887)

* WIP flux query basics

* WIP flux query basics

* WIP flux query basics

* WIP flux query basics

* wrap up content for flux query basics

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* properly close code block on flux query basics

* Flux – query data (#2891)

* added query data sources with flux and query influxdb

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Update content/flux/v0.x/query-data/influxdb.md

* Query Prometheus with Flux (#2893)

* query prometheus with flux

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Query CSV data with Flux (#2895)

* query csv data with flux

* address PR feedback

* Update content/flux/v0.x/query-data/csv.md

* update flux query data sources landing page

* updated flux query data doc formats and links

* Query SQL databases (#2922)

* WIP query sql guides

* query SQL data sources, closes #1738

* updated related link on sql.from

* added link to stream of tables and updated text

* updated connection string text

* updated query sql landing page and children hr styles

* updated sql query docs to address PR feedback

* added missing colon

* Query Google Cloud Bigtable with Flux (#2928)

* Query Google Cloud Bigtable with Flux

* updated doc structure of query bigtable doc

* fixed typo in bigquery doc

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>
Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Work with Flux data types (#2967)

* scaffolding for flux types, work with strings

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* removed note about interpolation vs concatenation

* updated wording of variable type association

* generalized type inference

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* WIP work with ints

* reverted int content

* updated strings doc to address PR feedback

* added description to data types landing page

* Apply suggestions from code review

* Update content/flux/v0.x/data-types/basic/string.md

* updated composite front-matter

* Work with time types in Flux  (#2974)

* work with time types in flux, closes #2260

* updated time type doc

* fixed type in time type description

* fixed typo

* updated work with time doc

* fixed typos

* updated verbiage

* added related links

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* updated time type doc to address PR feedback

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with booleans (#2975)

* work with boolean types

* updated working with booleans

* updated verbiage

* added related links

* Update content/flux/v0.x/data-types/basic/boolean.md

* Work with bytes types (#2976)

* work with bytes types

* added toc to bytes type doc

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* updated work with bytes doc

* fixed typo

* added related links

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Work with durations (#2977)

* work with durations in flux

* added keywords to duration doc to improve searchability

* minor updates to duration type doc

* updated verbiage

* added related links and removed toDuration from menu

* Update content/flux/v0.x/data-types/basic/duration.md

* Work with null types (#2978)

* WIP null types

* work with null types in flux

* updated null types doc

* Update content/flux/v0.x/data-types/basic/null.md

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with floats (#2979)

* work with floats in flux

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Apply suggestions from code review

* updated floats type doc

* Update content/flux/v0.x/data-types/basic/float.md

* updated verbiage

* added related links

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with integers (#2980)

* WIP work with ints

* work with integers

* work with integers

* updated float to int behavior, added related links, closes #2973

* added toc to ints doc

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Update content/flux/v0.x/data-types/basic/integer.md

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with uintegers (#2981)

* WIP work with uints

* work with uints

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* fixed minor type

* Work with records (#2982)

* work with records in flux

* updated record type doc

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with arrays (#2983)

* work with arrays

* added array.from example, added related links

* Work with dictionaries (#2984)

* WIP work with dicts

* work with dictionaries

* added related links to dict package

* added introduced version to dict package

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* added sample dict output

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Work with functions (#2985)

* work with functions

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* revamped type landing pages

* marked union types as draft

* miscellaneous updates

* Work with regular expression (#3024)

* work with regular expression types, closes #2573, closes influxdata/flux#3741

* add context for quoteMeta function

* Apply suggestions from code review

Co-authored-by: Jason Stirnaman <jstirnaman@influxdata.com>

Co-authored-by: Jason Stirnaman <jstirnaman@influxdata.com>

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>
Co-authored-by: Jason Stirnaman <jstirnaman@influxdata.com>

* fix latest links in page descriptions

* updated influxdb links

* Flux syntax basics (#3033)

* flux syntax basics

* Apply suggestions from code review

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>

* updated function description

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Apply suggestions from code review

* Update content/flux/v0.x/get-started/syntax-basics.md

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>
Co-authored-by: Jason Stirnaman <jstirnaman@influxdata.com>

* added table param to transformations, closes #2392 (#3039)

* updated flux function links

* update algolia configuration to fix search, closes #1902 (#3042)

* ported notes in the from function doc

* Flux package options (#3083)

* add now option to universe package

* added missing package options, closes #2464

* addressed PR feedback

* Flux transformation input/output examples (#3103)

* added flux/sample shortcode

* standardize flux package titles and list titles

* added start and stop columns as an option with flux/sample shortcode

* minor updates to stdlib

* WIP add input and output examples to flux transformations

* WIP removed sample data demo from universe index page

* WIP function input and output examples

* WIP flux input output examples

* WIP flux input output examples

* flux transformation input and output examples

* Add Flux 'sampledata' package (#3088)

* add flux sampledata package

* updated sampledata example titles

* Write data with Flux (#3084)

* WIP write to sql data sources

* write to sql data sources

* added write data to influxdb with flux doc

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* made sql headings specific to each db

* updated write to influxdb

* added tag to influxdb to example

* restructred influxdb write examples as code tabs

Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>

* fixed list on influxdb write with flux page

* Flux move changelog (#3117)

* updated flux redirects in edge.js

* move flux changelog into Flux restructure

* add flux redirects to edge.js

* removed extra parentheses from monitor.notify examples, closes #2505

* updated flux release notes with flux 0.129.0

* moved from and to into the influxdata/influxdb package

* updated notes on to and from docs

* added flux card to homepage

* added flux-0.130.0 to flux release notes

* flux link cleanup

* updated experimental message, closes #3097 (#3128)

* Remove Flux stdlib and language from InfluxDB (#3133)

* remove flux stdlib and lang from influxdb, update flux get-started, closes #2132

* flux link cleanup

* cleaned up prometheus verbiage, updated flux data type links

* function cleanup

* fixed sidenav toggle button

* updated group key links, added aliases for flux landing page

* fixed broken links, commented out prometheus content, updated flux types names

* added flux links to the left nav

* fixed flux links in kapacitor docs

* temporarily disable search (#3134)

* merged master and updated telegraf plugins

Co-authored-by: pierwill <19642016+pierwill@users.noreply.github.com>
Co-authored-by: kelseiv <47797004+kelseiv@users.noreply.github.com>
Co-authored-by: Jason Stirnaman <jstirnaman@influxdata.com>
pull/3142/head
Scott Anderson 2021-09-16 16:19:21 -06:00 committed by GitHub
parent 9bab86012a
commit 93aa238dc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1420 changed files with 31601 additions and 36714 deletions

View File

@ -510,6 +510,27 @@ The following colors are available:
{{< req color="magenta" text="This is required" >}}
```
### Page navigation buttons
Use the `{{< page-nav >}}` shortcode to add page navigation buttons to a page.
These are useful for guiding users through a set of docs that should be read in sequential order.
The shortcode has the following parameters:
- **prev:** path of the previous document _(optional)_
- **next:** path of the next document _(optional)_
- **prevText:** override the button text linking to the previous document _(optional)_
- **nextText:** override the button text linking to the next document _(optional)_
The shortcode generates buttons that link to both the previous and next documents.
By default, the shortcode uses either the `list_title` or the `title` of the linked
document, but you can use `prevText` and `nextText` to override button text.
```md
<!-- Simple example -->
{{ page-nav prev="/path/to/prev/" next="/path/to/next" >}}
<!-- Override button text -->
{{ page-nav prev="/path/to/prev/" prevText="Previous" next="/path/to/next" nextText="Next" >}}
### Keybinds
Use the `{{< keybind >}}` shortcode to include OS-specific keybindings/hotkeys.
The following parameters are available:
@ -683,7 +704,7 @@ To include a horizontal rule after each child summary, set `hr=true`.
_Only the `articles` list type supports horizontal rules._
```md
{{< children readmore=true >}}
{{< children hr=true >}}
```
#### Include a code example with a child summary
@ -931,6 +952,52 @@ I like {{< tooltip "Butterflies are awesome!" "butterflies" >}}.
The example above renders as "I like butterflies" with "butterflies" highlighted.
When you hover over "butterflies," a tooltip appears with the text: "Butterflies are awesome!"
### Flux sample data tables
The Flux `sample` package provides basic sample datasets that can be used to
illustrate how Flux functions work. To quickly display one of the raw sample
datasets, use the `{{% flux/sample %}}` shortcode.
The `flux/sample` shortcode has the following arguments that can be specified
by name or positionally.
#### set
Sample dataset to output. Use either `set` argument name or provide the set
as the first argument. The following sets are available:
- float
- int
- uint
- string
- bool
- numericBool
#### includeNull
Specify whether or not to include _null_ values in the dataset.
Use either `includeNull` argument name or provide the boolean value as the second argument.
#### includeRange
Specify whether or not to include time range columns (`_start` and `_stop`) in the dataset.
This is only recommended when showing how functions that require a time range
(such as `window()`) operate on input data.
Use either `includeRange` argument name or provide the boolean value as the third argument.
##### Example Flux sample data shortcodes
```md
<!-- No arguments, defaults to "float" set without nulls -->
{{% flux/sample %}}
<!-- Output the "string" set without nulls or time range columns -->
{{% flux/sample set="string" includeNull=false %}}
<!-- Output the "int" set with nulls but without time range columns -->
{{% flux/sample "int" true %}}
<!-- Output the "int" set with nulls and time range columns -->
<!-- The following shortcode examples render the same -->
{{% flux/sample set="int" includeNull=true includeRange=true %}}
{{% flux/sample "int" true true %}}
```
### Reference content
The InfluxDB documentation is "task-based," meaning content primarily focuses on
what a user is **doing**, not what they are **using**.

View File

@ -0,0 +1,157 @@
var tablesElement = $("#flux-group-keys-demo #grouped-tables")
// Sample data
let data = [
[
{ _time: "2021-01-01T00:00:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "temp", _value: 110.3 },
{ _time: "2021-01-01T00:01:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "temp", _value: 112.5 },
{ _time: "2021-01-01T00:02:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "temp", _value: 111.9 }
],
[
{ _time: "2021-01-01T00:00:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "hum", _value: 73.4 },
{ _time: "2021-01-01T00:01:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "hum", _value: 73.7 },
{ _time: "2021-01-01T00:02:00Z", _measurement: "example", loc: "rm1", sensorID: "A123", _field: "hum", _value: 75.1 }
],
[
{ _time: "2021-01-01T00:00:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "temp", _value: 108.2 },
{ _time: "2021-01-01T00:01:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "temp", _value: 108.5 },
{ _time: "2021-01-01T00:02:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "temp", _value: 109.6 }
],
[
{ _time: "2021-01-01T00:00:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "hum", _value: 71.8 },
{ _time: "2021-01-01T00:01:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "hum", _value: 72.3 },
{ _time: "2021-01-01T00:02:00Z", _measurement: "example", loc: "rm2", sensorID: "B456", _field: "hum", _value: 72.1 }
]
]
// Default group key
let groupKey = ["_measurement", "loc", "sensorID", "_field"]
// Build a table group (group key and table) using an array of objects
function buildTable(inputData) {
// Build the group key string
function wrapString(column, value) {
var stringColumns = ["_measurement", "loc", "sensorID", "_field"]
if (stringColumns.includes(column)) {
return '"' + value + '"'
} else {
return value
}
}
var groupKeyString = "Group key = [" + (groupKey.map(column => column + ": " + wrapString(column, (inputData[0])[column])) ).join(", ") + "]";
var groupKeyLabel = document.createElement("p");
groupKeyLabel.className = "table-group-key"
groupKeyLabel.innerHTML = groupKeyString
// Extract column headers
var columns = [];
for (var i = 0; i < inputData.length; i++) {
for (var key in inputData[i]) {
if (columns.indexOf(key) === -1) {
columns.push(key);
}
}
}
// Create the table element
var table = document.createElement("table");
// Create the table header
for (let i = 0; i < columns.length; i++) {
var header = table.createTHead();
var th = document.createElement("th");
th.innerHTML = columns[i];
if (groupKey.includes(columns[i])) {
th.className = "grouped-by";
}
header.appendChild(th);
}
// Add inputData to the HTML table
for (let i = 0; i < inputData.length; i++) {
tr = table.insertRow(-1);
for (let j = 0; j < columns.length; j++) {
var td = tr.insertCell(-1);
td.innerHTML = inputData[i][columns[j]];
// Highlight the value if column is part of the group key
if (groupKey.includes(columns[j])) {
td.className = "grouped-by";
}
}
}
// Create a table group with group key and table
var tableGroup = document.createElement("div");
tableGroup.innerHTML += groupKeyLabel.outerHTML + table.outerHTML
return tableGroup
}
// Clear and rebuild all HTML tables
function buildTables(data) {
existingTables = tablesElement[0]
while (existingTables.firstChild) {
existingTables.removeChild(existingTables.firstChild);
}
for (let i = 0; i < data.length; i++) {
var table = buildTable(data[i])
tablesElement.append(table);
}
}
// Group data based on the group key and output new tables
function groupData() {
let groupedData = data.flat()
function groupBy(array, f) {
var groups = {};
array.forEach(function (o) {
var group = JSON.stringify(f(o));
groups[group] = groups[group] || [];
groups[group].push(o);
});
return Object.keys(groups).map(function (group) {
return groups[group];
})
}
groupedData = groupBy(groupedData, function (r) {
return groupKey.map(v => r[v]);
});
buildTables(groupedData);
}
// Get selected column names
var checkboxes = $("input[type=checkbox]");
function getChecked() {
var checked = [];
for (var i = 0; i < checkboxes.length; i++) {
var checkbox = checkboxes[i];
if (checkbox.checked) checked.push(checkbox.name);
}
return checked;
}
function toggleCheckbox(element) {
element.checked = !element.checked;
}
// Build example group function
function buildGroupExample() {
var columnCollection = getChecked().map(i => '<span class=\"s2\">"' + i + '"</span>').join(", ")
$("pre#group-by-example")[0].innerHTML = "data\n <span class='nx'>|></span> group(columns<span class='nx'>:</span> [" + columnCollection + "])";
}
$(".column-list label").click(function () {
toggleCheckbox($(this))
groupKey = getChecked();
groupData();
buildGroupExample();
});
// Group and render tables on load
groupData()

View File

@ -4,8 +4,8 @@ function countTag(tag) {
}
function getFilterCounts() {
$('#plugin-filters label').each(function() {
var tagName = $('input', this).attr('name').replace(/[\W]+/, "-");
$('#list-filters label').each(function() {
var tagName = $('input', this).attr('name').replace(/[\W/]+/, "-");
var tagCount = countTag(tagName);
$(this).attr('data-count', '(' + tagCount + ')');
if (tagCount <= 0) {
@ -19,29 +19,29 @@ function getFilterCounts() {
// Get initial filter count on page load
getFilterCounts()
$("#plugin-filters input").click(function() {
$("#list-filters input").click(function() {
// List of tags to hide
var tagArray = $("#plugin-filters input:checkbox:checked").map(function(){
var tagArray = $("#list-filters input:checkbox:checked").map(function(){
return $(this).attr('name').replace(/[\W]+/, "-");
}).get();
// List of tags to restore
var restoreArray = $("#plugin-filters input:checkbox:not(:checked)").map(function(){
var restoreArray = $("#list-filters input:checkbox:not(:checked)").map(function(){
return $(this).attr('name').replace(/[\W]+/, "-");
}).get();
// Actions for filter select
if ( $(this).is(':checked') ) {
$.each( tagArray, function( index, value ) {
$(".plugin-card.visible:not([data-tags~='" + value + "'])").removeClass('visible').fadeOut()
$(".filter-item.visible:not([data-tags~='" + value + "'])").removeClass('visible').fadeOut()
})
} else {
$.each( restoreArray, function( index, value ) {
$(".plugin-card:not(.visible)[data-tags~='" + value + "']").addClass('visible').fadeIn()
$(".filter-item:not(.visible)[data-tags~='" + value + "']").addClass('visible').fadeIn()
})
$.each( tagArray, function( index, value ) {
$(".plugin-card.visible:not([data-tags~='" + value + "'])").removeClass('visible').hide()
$(".filter-item.visible:not([data-tags~='" + value + "'])").removeClass('visible').hide()
})
}

View File

@ -22,10 +22,11 @@
& + pre { margin-top: .5rem }
& + .code-tabs-wrapper { margin-top: 0; }
}
.title { margin-bottom: 2.65rem; }
h1 {
font-weight: normal;
font-size: 2.65rem;
margin: .4em 0 1em;
margin: .4em 0 .2em;
}
h2 {
font-size: 2rem;
@ -112,8 +113,10 @@
"article/expand",
"article/feedback",
"article/flex",
"article/flux",
"article/html-diagrams",
"article/keybinding",
"article/list-filters",
"article/lists",
"article/note",
"article/pagination-btns",
@ -170,6 +173,17 @@
&:hover {opacity: 1;}
}
p.read-more {
text-align: right;
font-style: italic;
}
.highlight, pre, code, .flex-wrapper {
& + p.read-more {
margin: -.75rem 0 .5rem;
}
}
/////////////////////////// Getting Started Buttons //////////////////////////
.get-started-btns {
@ -197,7 +211,10 @@
.article {
padding: 1.5rem 1.5rem 3rem;
h1 { margin: .35rem 0 2rem; font-size: 2.4rem; }
.title {
margin-bottom: 2rem;
h1 { margin: .35em 0 .2em; font-size: 2.4rem; }
}
h2 { font-size: 1.9rem; }
h3 { font-size: 1.55rem; }
h4 { font-size: 1.3rem; }

View File

@ -7,6 +7,7 @@
font-weight: $medium;
color: $g20-white;
box-shadow: 2px 2px 6px rgba($g2-kevlar, .35);
z-index: 1;
// temp styles for animation
transition: margin .3s ease-out;

View File

@ -177,6 +177,55 @@
}
}
#flux {
padding-bottom: 2.5rem;
.card .card-content {
h2 {margin-bottom: .5rem;}
p {margin: 0 0 1rem;}
}
.card.flux-btns {
flex-direction: row;
margin-bottom: .75rem;
justify-content: flex-end;
align-items: center;
a.btn {
position: relative;
display: inline-block;
text-align: center;
margin: .5rem .5rem .5rem 0;
padding: .75rem 1.5rem;
color: $article-btn-text !important;
border-radius: $radius;
font-size: .95rem;
z-index: 1;
@include gradient($article-btn-gradient);
&:after {
content: "";
position: absolute;
display: block;
top: 0;
right: 0;
width: 100%;
height: 100%;
border-radius: $radius;
@include gradient($article-btn-gradient-hover);
opacity: 0;
transition: opacity .2s;
z-index: -1;
}
&:hover {
cursor: pointer;
&:after {
opacity: 1;
}
}
}
}
}
#tick-cards {
display: flex;
flex-wrap: wrap;
@ -260,6 +309,10 @@
.quarter { width: 33.33%; }
.three-quarters { width: 66.64%; }
}
#flux .card.flux-btns {
flex-direction: column;
align-items: flex-end;
}
}
@media (max-width: 920px) {
@ -268,7 +321,7 @@
padding-right: 1.5rem;
&.hero { padding-top: 2rem; padding-bottom: 3rem;}
&.search,
&#enterprise { padding-top: 1.5rem; padding-bottom: 1.5rem; }
&#enterprise, &#flux { padding-top: 1.5rem; padding-bottom: 1.5rem; }
}
.hero {
#hero-img{ display: none; }
@ -327,29 +380,35 @@
}
}
}
&#flux {
order: 3; padding-left: 0; padding-right: 0;
.card.flux-btns {
padding-top: 0;
a.btn {
display: block;
width: 100%;
margin: 0 0 .5rem;
}
}
}
&#tick-stack {
order: 3;
order: 4;
padding-left: 0;
padding-right: 0;
#tick-cards {
flex-direction: column;
.card {
width: 100%;
color: $g20-white;
a {color: $g20-white;}
&:after { opacity: 1; }
border-top: 1px solid rgba($article-text, .15);
}
}
}
&#enterprise { order: 4; padding-left: 0; padding-right: 0; }
&#enterprise { order: 5; padding-left: 0; padding-right: 0; }
}
.group-wrapper {flex-direction: column;}
.row {
flex-direction: column;
}
.card {
}
}
}

View File

@ -284,13 +284,15 @@
font-size: .85rem;
letter-spacing: .08rem;
&.platform:after {
content: "\e911";
font-family: "icomoon";
font-style: normal;
font-size: 1rem;
opacity: .4;
margin-left: .25rem;
&.platform, &.flux {
&:after {
content: "\e911";
font-family: "icomoon";
font-style: normal;
font-size: 1rem;
opacity: .4;
margin-left: .25rem;
}
}
}
}

View File

@ -170,9 +170,9 @@ pre[class*="language-"] {
.w /* Text.Whitespace */
{ font-style: italic }
// Javascript / Flux specific styles (duration values)
// Javascript / Flux specific styles (duration and time values)
.language-js {
.mi + .nx { color: $article-code-accent5; }
.mi + .nx, .mf + .nx { color: $article-code-accent5; }
}
// SQL / InfluxQL specific styles (duration values)

View File

@ -98,12 +98,34 @@
list-style: none;
display: flex;
flex-direction: column-reverse;
&.products{
li {
&:before {
display: inline-block;
font-size: .8rem;
color: $g2-kevlar;
font-style: italic;
font-weight: bold;
opacity: .65;
mix-blend-mode: multiply;
}
&:last-child:before {
content: "Products";
margin: .3rem .75rem .15rem;
}
&.flux:before {
content: "Languages";
margin: .75rem .75rem .15rem;
}
}
}
}
a {
display: block;
text-decoration: none;
color: $g20-white;
padding: .5rem 1.5rem .5rem .75rem;
padding: .4rem 1.5rem .4rem .75rem;
background: rgba($g20-white, 0);
&:hover { background: rgba($g20-white, .2) }
&.active { background: rgba($g20-white, .2) }

View File

@ -1,7 +1,7 @@
.caption {
margin: -2rem 0 2rem;
padding-left: .25rem;
font-size: .8rem;
font-size: .85rem;
font-style: italic;
opacity: .8;

View File

@ -16,4 +16,5 @@
&:after { color: $article-link; }
}
}
& > hr:last-child {display: none}
}

View File

@ -18,7 +18,7 @@
cursor: pointer;
&:hover {
.expand-toggle { background: $article-link; }
.expand-toggle { background: $b-laser; }
}
}
@ -27,7 +27,7 @@
display: inline-block;
min-height: 20px;
min-width: 20px;
background: rgba($article-text, .25);
background: $b-dodger;
border-radius: 50%;
margin-right: .75rem;
transition: background-color .2s;

View File

@ -13,8 +13,8 @@
&.quarter { width: calc(25% - 1rem); }
&.two-thirds { width: calc(66% - 2rem);}
table {
margin-bottom: 1rem;
&.half, &.third, &.quarter {
table:not(:last-child) {margin-right: 1rem;}
}
}

View File

@ -0,0 +1,299 @@
//////////////////////// Styles unique to the Flux docs ////////////////////////
.title .meta {
margin-bottom: 0;
padding: 0 .65em 0 .75em;
color: $article-heading;
background: rgba($article-heading, .07);
font-size: .9rem;
font-weight: $medium;
border-radius: 1em;
display: inline-block;
}
h2,h3,h4 {
&:after {
content: attr(data-type);
display: inline-block;
margin-left: .5rem;
font-style: italic;
font-size: .62em;
font-weight: 200;
opacity: .5;
}
}
#flux-group-keys-demo {
table {
margin-bottom: 1.25rem;
td, th {
&:first-child {text-align: left;}
&:last-child {text-align: right;}
&.grouped-by {font-weight: bold;}
}
th.grouped-by {color: $tooltip-color-alt;}
td.grouped-by {color: $tooltip-color}
}
#group-by-columns {
.column-list {
padding: 0;
margin: .5rem 0 0;
list-style: none;
li {
margin: 0;
line-height: 1.35rem;
}
}
label {
display: inline-block;
padding: .25rem 0;
color: $article-text;
position: relative;
&:after {
content: attr(data-count);
margin-left: 0;
font-size: .85rem;
opacity: .5;
}
}
.checkbox {
display: inline-block;
position: relative;
height: 1.15em;
width: 1.15em;
background: rgba($article-text, .05);
margin-right: .3rem;
vertical-align: text-top;
border-radius: $radius;
cursor: pointer;
border: 1.5px solid rgba($article-text, .2);
user-select: none;
}
input[type='checkbox'] {
margin-right: -1.1rem ;
padding: 0;
vertical-align: top;
opacity: 0;
cursor: pointer;
& + .checkbox:after {
content: "";
display: block;
position: absolute;
height: .5rem;
width: .5rem;
border-radius: 50%;
background: $article-link;
top: 50%;
left: 50%;
opacity: 0;
transform: scale(2) translate(-20%, -20%);
transition: all .2s;
}
&:checked + .checkbox:after {
opacity: 1;
transform: scale(1) translate(-50%, -50%);
}
}
}
pre#group-by-example {
line-height: 1.4rem;
font-size: .95rem;
.nx { color: $article-code-accent2; }
.s2 { color: $article-code-accent3; }
}
}
.flux-water-diagram {
background: $flux-water-process-img;
margin: 2rem 0 .5rem;
width: 100%;
height: 0;
padding-top: 63.71%;
background-repeat: no-repeat;
}
//////////////////////////// Flux Data Model Diagram ///////////////////////////
#flux-data-model {
max-width: 500px;
margin: 3rem 0;
.stream-of-tables{
position: relative;
border: 1px dashed $article-text;
padding: 1rem;
border-radius: $radius * 2;
&:before {
content: "Stream of tables";
font-weight: $medium;
color: $article-bold;
background: $article-bg;
position: absolute;
padding: 0 1rem;
top: -.65rem;
}
}
table {
display: table;
width: 100%;
overflow: visible;
margin: 0;
th, td {
border-right: 1px dashed rgba($article-text, .25);
&:last-child { border: none; }
}
th { border-color: rgba($g20-white, .25); }
}
.table-group {
padding: 1rem;
// Table outline
&:first-child {
border: 1px dashed $article-text;
border-radius: $radius;
position: relative;
margin-bottom: .25rem;
&:before {
content: "Table";
font-weight: $medium;
color: $article-bold;
background: $article-bg;
position: absolute;
padding: 0 .75rem;
top: -.65rem;
right: 1rem;
}
}
// Column outline
&:nth-child(2) {
th{
&:first-child { border: none; }
&:nth-child(2) {
border-top: 1px dashed $article-text;
border-left: 1px dashed rgba($g20-white, .85);
border-right: 1px dashed rgba($g20-white, .85);
position: relative;
&:before {
content: "Column";
font-weight: $medium;
color: $g20-white, .85;
position: absolute;
top: .2rem;
left: .5rem;
}
}
}
td{
&:first-child { border: none; }
&:nth-child(2) {
border-left: 1px dashed $article-text;
border-right: 1px dashed $article-text;
}
}
tr:last-child td:nth-child(2) { border-bottom: 1px dashed $article-text; }
}
// Row outline
&:nth-child(3) {
tr:nth-child(2) {
border-top: 1px dashed $article-text;
border-bottom: 1px dashed $article-text;
td:first-child {
border-left: 1px dashed $article-text;
position: relative;
&:before {
content: "Row";
font-weight: $medium;
color: $article-bold;
position: absolute;
top: .15rem;
left: .5rem;
}
}
td:last-child { border-right: 1px dashed $article-text }
}
}
}
}
///////////////////////// Flux Table Operations Diagram ////////////////////////
#flux-table-ops {
display: flex;
justify-content: space-between;
align-items: center;
max-width: 650px;
margin-bottom: 2rem;
.stream-of-tables {
flex-grow: 1;
&:first-child { padding-left: 0; }
&:last-child { padding-right: 0; }
}
.operation {
display: flex;
flex-grow: 1;
align-items: center;
.arrow {
position: relative;
background: $article-text;
flex-grow: 1;
height: 1px;
margin: 0 .75rem;
opacity: .35;
&:after {
content: "";
position: absolute;
width: 0;
height: 0;
border-style: solid;
border-width: 7px 0 7px 8px;
border-color: transparent transparent transparent $article-text;
right: -1px;
top: -7px;
}
}
p { margin: 0; text-align: center;}
}
table {
display: table;
width: 100%;
overflow: visible;
margin: 1rem 0;
th, td {
border-right: 1px dashed rgba($article-text, .25);
&:last-child { border: none; }
}
th { border-color: rgba($g20-white, .25); }
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// MEDIA QUERIES ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@include media(small) {
#flux-table-ops {
th, td {
&:last-child { display: none; }
&:nth-child(2) { border: none; }
}
th:nth-child(2) { border-radius: 0 $radius 0 0;}
tr:last-child td:nth-child(2) {border-radius: 0 0 $radius 0;}
}
}

View File

@ -103,7 +103,9 @@
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// MEDIA QUERIES ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@include media(small) {
#shard-diagram {

View File

@ -0,0 +1,115 @@
//////////////////////////////// Plugin Filters ////////////////////////////////
#list-filters {
display: flex;
flex-flow: row wrap;
align-items: flex-start;
.filter-category {
flex: 1 1 200px;
margin: 0 1.25rem 1.25rem 0;
max-width: 33%;
&.two-columns {
flex: 1 2 400px;
max-width: 66%;
.filter-list {
columns: 2;
}
}
}
h5 {
border-bottom: 1px solid rgba($article-text, .25);
padding-bottom: .65rem;
}
.filter-list {
padding: 0;
margin: .5rem 0 0;
list-style: none;
li {
margin: 0;
line-height: 1.35rem;
}
}
label {
display: block;
padding: .25rem 0;
color: $article-text;
position: relative;
&:after {
content: attr(data-count);
margin-left: 0;
font-size: .85rem;
opacity: .5;
}
}
.checkbox {
display: inline-block;
position: relative;
height: 1.15em;
width: 1.15em;
background: rgba($article-text, .05);
margin-right: .3rem;
vertical-align: text-top;
border-radius: $radius;
cursor: pointer;
border: 1.5px solid rgba($article-text, .2);
user-select: none;
}
input[type='checkbox'] {
margin-right: -1.1rem ;
padding: 0;
vertical-align: top;
opacity: 0;
cursor: pointer;
& + .checkbox:after {
content: "";
display: block;
position: absolute;
height: .5rem;
width: .5rem;
border-radius: 50%;
background: $article-link;
top: 50%;
left: 50%;
opacity: 0;
transform: scale(2) translate(-20%, -20%);
transition: all .2s;
}
&:checked + .checkbox:after {
opacity: 1;
transform: scale(1) translate(-50%, -50%);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// MEDIA QUERIES ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@media(max-width: 1100px) {
#list-filters {
.filter-category {
max-width: 50%;
&.two-columns, &.three-columns {
max-width: 100%;
}
}
}
}
@include media(small) {
#list-filters{
.filter-category {
max-width: 100%;
}
}
}

View File

@ -13,3 +13,8 @@
line-height: 1.25rem;
}
}
.expand-wrapper + .related {
border-top: none;
margin-top: -2rem;
}

View File

@ -51,6 +51,10 @@ table {
img { margin-bottom: 0; }
}
table + table {
margin-top: -1.5rem;
}
#flags:not(.no-shorthand), #global-flags {
& + table {
td:nth-child(2) code { margin-left: -2rem; }

View File

@ -26,8 +26,10 @@
}
}
.related + .tags {
border: none;
padding-top: 0;
margin: 1.5rem 0 1rem;
}
.related, .expand-wrapper{
& + .tags {
border: none;
padding-top: 0;
margin: 1.5rem 0 1rem;
}
}

View File

@ -21,6 +21,7 @@
font-style: italic;
color: $nav-active;
font-size: 1.2rem;
opacity: 1;
}
p {
@ -104,120 +105,11 @@
}
}
//////////////////////////////// Plugin Filters ////////////////////////////////
#plugin-filters {
display: flex;
flex-flow: row wrap;
align-items: flex-start;
.filter-category {
flex: 1 1 200px;
margin: 0 1.25rem 1.25rem 0;
max-width: 33%;
&.two-columns {
flex: 1 2 400px;
max-width: 66%;
.filter-list {
columns: 2;
}
}
}
h5 {
border-bottom: 1px solid rgba($article-text, .25);
padding-bottom: .65rem;
}
.filter-list {
padding: 0;
margin: .5rem 0 0;
list-style: none;
li {
margin: 0;
line-height: 1.35rem;
}
}
label {
display: block;
padding: .25rem 0;
color: $article-text;
position: relative;
&:after {
content: attr(data-count);
margin-left: 0;
font-size: .85rem;
opacity: .5;
}
}
.checkbox {
display: inline-block;
position: relative;
height: 1.15em;
width: 1.15em;
background: rgba($article-text, .05);
margin-right: .3rem;
vertical-align: text-top;
border-radius: $radius;
cursor: pointer;
border: 1.5px solid rgba($article-text, .2);
user-select: none;
}
input[type='checkbox'] {
margin-right: -1.1rem ;
padding: 0;
vertical-align: top;
opacity: 0;
cursor: pointer;
& + .checkbox:after {
content: "";
display: block;
position: absolute;
height: .5rem;
width: .5rem;
border-radius: 50%;
background: $article-link;
top: 50%;
left: 50%;
opacity: 0;
transform: scale(2) translate(-20%, -20%);
transition: all .2s;
}
&:checked + .checkbox:after {
opacity: 1;
transform: scale(1) translate(-50%, -50%);
}
}
}
////////////////////////////////////////////////////////////////////////////////
///////////////////////////////// MEDIA QUERIES ////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
@media(max-width: 1100px) {
#plugin-filters {
.filter-category {
max-width: 50%;
&.two-columns, &.three-columns {
max-width: 100%;
}
}
}
}
@include media(small) {
#plugin-filters{
.filter-category {
max-width: 100%;
}
}
.plugin-card {
.github-link {

View File

@ -215,6 +215,8 @@ $html-diagram-shard-group-bg: $article-table-row-alt;
// Diagram colors
$diagram-arrow: $g6-smoke;
$flux-water-process-img: url('/img/flux/0-x-water-process-dark.svg');
@import "dark/telegraf",
"dark/chronograf",
"dark/kapacitor";

View File

@ -211,6 +211,8 @@ $svg-geo-point: $p-potassium !default;
$html-diagram-shard-group-bg: $g20-white !default;
$flux-water-process-img: url('/img/flux/0-x-water-process-light.svg') !default;
// Diagram colors
$diagram-arrow: $g14-chromium !default;

View File

@ -23,6 +23,7 @@ smartDashes = false
[taxonomies]
"influxdb/v2.0/tag" = "influxdb/v2.0/tags"
"influxdb/cloud/tag" = "influxdb/cloud/tags"
"flux/v0.x/tag" = "flux/v0.x/tags"
[markup]
[markup.goldmark]

View File

@ -15,7 +15,7 @@ The next steps will get you up and running with the second essential component o
your InfluxDB Enterprise cluster: the data nodes.
If you have not set up your meta nodes, please visit
[Installing meta nodes](/enterprise_influxdb//v1.6/install-and-deploy/production_installation/meta_node_installation/).
[Installing meta nodes](/enterprise_influxdb/v1.6/install-and-deploy/production_installation/meta_node_installation/).
Bad things can happen if you complete the following steps without meta nodes.
<br>

View File

@ -34,7 +34,7 @@ This article outlines many of the tasks possible with Flux but not InfluxQL and
### Joins
InfluxQL has never supported joins. They can be accomplished using [TICKscript](/{{< latest "kapacitor" >}}/tick/introduction/),
but even TICKscript's join capabilities are limited.
Flux's [`join()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/join/) allows you
Flux's [`join()` function](/{{< latest "flux" >}}/stdlib/universe/join/) lets you
to join data **from any bucket, any measurement, and on any columns** as long as
each data set includes the columns on which they are to be joined.
This opens the door for really powerful and useful operations.
@ -106,7 +106,7 @@ join(
### Sort by tags
InfluxQL's sorting capabilities are very limited, allowing you only to control the
sort order of `time` using the `ORDER BY time` clause.
Flux's [`sort()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/sort) sorts records based on list of columns.
Flux's [`sort()` function](/{{< latest "flux" >}}/stdlib/universer/sort) sorts records based on list of columns.
Depending on the column type, records are sorted lexicographically, numerically, or chronologically.
```js
@ -122,7 +122,7 @@ from(bucket:"telegraf/autogen")
### Group by any column
InfluxQL lets you group by tags or by time intervals, but nothing else.
Flux lets you group by any column in the dataset, including `_value`.
Use the Flux [`group()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/group/)
Use the Flux [`group()` function](/{{< latest "flux" >}}/stdlib/universe/group/)
to define which columns to group data by.
```js
@ -149,9 +149,9 @@ InfluxQL can only query data stored in InfluxDB.
Flux can query data from other data sources such as CSV, PostgreSQL, MySQL, Google BigTable, and more.
Join that data with data in InfluxDB to enrich query results.
- [Flux CSV package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/csv/)
- [Flux SQL package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/sql/)
- [Flux BigTable package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/bigtable/)
- [Flux CSV package](/{{< latest "flux" >}}/stdlib/csv/)
- [Flux SQL package](/{{< latest "flux" >}}/stdlib/sql/)
- [Flux BigTable package](/{{< latest "flux" >}}/stdlib/experimental/bigtable/)
<!-- -->
```js
@ -183,7 +183,7 @@ _For an in-depth walkthrough of querying SQL data, see [Query SQL data sources](
### DatePart-like queries
InfluxQL doesn't support DatePart-like queries that only return results during specified hours of the day.
The Flux [`hourSelection` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/hourselection/)
The Flux [`hourSelection` function](/{{< latest "flux" >}}/stdlib/universe/hourselection/)
returns only data with time values in a specified hour range.
```js
@ -198,7 +198,7 @@ from(bucket: "telegraf/autogen")
### Pivot
Pivoting data tables has never been supported in InfluxQL.
The Flux [`pivot()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/pivot) provides the ability
The Flux [`pivot()` function](/{{< latest "flux" >}}/stdlib/universe/pivot) provides the ability
to pivot data tables by specifying `rowKey`, `columnKey`, and `valueColumn` parameters.
```js
@ -217,7 +217,7 @@ from(bucket: "telegraf/autogen")
### Histograms
The ability to generate histograms has been a highly requested feature for InfluxQL, but has never been supported.
Flux's [`histogram()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/histogram) uses input
Flux's [`histogram()` function](/{{< latest "flux" >}}/stdlib/universe/histogram) uses input
data to generate a cumulative histogram with support for other histogram types coming in the future.
```js
@ -240,8 +240,8 @@ _For an example of using Flux to create a cumulative histogram, see [Create hist
### Covariance
Flux provides functions for simple covariance calculation.
The [`covariance()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/covariance)
calculates the covariance between two columns and the [`cov()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/cov)
The [`covariance()` function](/{{< latest "flux" >}}/stdlib/universe/covariance)
calculates the covariance between two columns and the [`cov()` function](/{{< latest "flux" >}}/stdlib/universe/cov)
calculates the covariance between two data streams.
###### Covariance between two columns
@ -270,7 +270,7 @@ cov(x: table1, y: table2, on: ["_time", "_field"])
### Cast booleans to integers
InfluxQL supports type casting, but only for numeric data types (floats to integers and vice versa).
[Flux type conversion functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/)
[Flux type conversion functions](/{{< latest "flux" >}}/stdlib/universe/type-conversions/)
provide much broader support for type conversions and let you perform some long-requested
operations like casting a boolean values to integers.
@ -287,8 +287,8 @@ from(bucket: "telegraf/autogen")
### String manipulation and data shaping
InfluxQL doesn't support string manipulation when querying data.
The [Flux Strings package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/strings/) is a collection of functions that operate on string data.
When combined with the [`map()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/),
The [Flux Strings package](/{{< latest "flux" >}}/stdlib/strings/) is a collection of functions that operate on string data.
When combined with the [`map()` function](/{{< latest "flux" >}}/stdlib/universe/map/),
functions in the string package allow for operations like string sanitization and normalization.
```js
@ -310,7 +310,7 @@ from(bucket: "telegraf/autogen")
### Work with geo-temporal data
InfluxQL doesn't provide functionality for working with geo-temporal data.
The [Flux Geo package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/) is a collection of functions that
The [Flux Geo package](/{{< latest "flux" >}}/stdlib/experimental/geo/) is a collection of functions that
let you shape, filter, and group geo-temporal data.
```js
@ -332,88 +332,88 @@ from(bucket: "geo/autogen")
Flux is working towards complete parity with InfluxQL and new functions are being added to that end.
The table below shows InfluxQL statements, clauses, and functions along with their equivalent Flux functions.
_For a complete list of Flux functions, [view all Flux functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/all-functions)._
_For a complete list of Flux functions, [view all Flux functions](/{{< latest "flux" >}}/stdlib/all-functions)._
### InfluxQL and Flux parity
| InfluxQL | Flux Functions |
| -------- | -------------- |
| [SELECT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-basic-select-statement) | [filter()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/) |
| [WHERE](/enterprise_influxdb/v1.9/query_language/explore-data/#the-where-clause) | [filter()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/), [range()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/range/) |
| [GROUP BY](/enterprise_influxdb/v1.9/query_language/explore-data/#the-group-by-clause) | [group()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/group/) |
| [INTO](/enterprise_influxdb/v1.9/query_language/explore-data/#the-into-clause) | [to()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/outputs/to/) <span><a style="color:orange" href="#footnote">*</a></span> |
| [ORDER BY](/enterprise_influxdb/v1.9/query_language/explore-data/#order-by-time-desc) | [sort()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/sort/) |
| [LIMIT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-limit-clause) | [limit()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/limit/) |
| [SLIMIT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-slimit-clause) | -- |
| [OFFSET](/enterprise_influxdb/v1.9/query_language/explore-data/#the-offset-clause) | -- |
| [SOFFSET](/enterprise_influxdb/v1.9/query_language/explore-data/#the-soffset-clause) | -- |
| [SHOW DATABASES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-databases) | [buckets()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/buckets/) |
| [SHOW MEASUREMENTS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-measurements) | [v1.measurements](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/influxdb-v1/measurements) |
| [SHOW FIELD KEYS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-field-keys) | [keys()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/keys/) |
| [SHOW RETENTION POLICIES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-retention-policies) | [buckets()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/buckets/) |
| [SHOW TAG KEYS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-tag-keys) | [v1.tagKeys()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/influxdb-v1/tagkeys), [v1.measurementTagKeys()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/influxdb-v1/measurementtagkeys) |
| [SHOW TAG VALUES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-tag-values) | [v1.tagValues()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/influxdb-v1/tagvalues), [v1.measurementTagValues()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/influxdb-v1/measurementtagvalues) |
| [SHOW SERIES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-series) | -- |
| [CREATE DATABASE](/enterprise_influxdb/v1.9/query_language/manage-database/#create-database) | -- |
| [DROP DATABASE](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-a-database-with-drop-database) | -- |
| [DROP SERIES](/enterprise_influxdb/v1.9/query_language/manage-database/#drop-series-from-the-index-with-drop-series) | -- |
| [DELETE](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-series-with-delete) | -- |
| [DROP MEASUREMENT](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-measurements-with-drop-measurement) | -- |
| [DROP SHARD](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-a-shard-with-drop-shard) | -- |
| [CREATE RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#create-retention-policies-with-create-retention-policy) | -- |
| [ALTER RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#modify-retention-policies-with-alter-retention-policy) | -- |
| [DROP RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-retention-policies-with-drop-retention-policy) | -- |
| [COUNT](/enterprise_influxdb/v1.9/query_language/functions#count) | [count()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/count/) |
| [DISTINCT](/enterprise_influxdb/v1.9/query_language/functions#distinct) | [distinct()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/distinct/) |
| [INTEGRAL](/enterprise_influxdb/v1.9/query_language/functions#integral) | [integral()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/integral/) |
| [MEAN](/enterprise_influxdb/v1.9/query_language/functions#mean) | [mean()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/mean/) |
| [MEDIAN](/enterprise_influxdb/v1.9/query_language/functions#median) | [median()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/median/) |
| [MODE](/enterprise_influxdb/v1.9/query_language/functions#mode) | [mode()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/mode/) |
| [SPREAD](/enterprise_influxdb/v1.9/query_language/functions#spread) | [spread()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/spread/) |
| [STDDEV](/enterprise_influxdb/v1.9/query_language/functions#stddev) | [stddev()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/stddev/) |
| [SUM](/enterprise_influxdb/v1.9/query_language/functions#sum) | [sum()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/sum/) |
| [BOTTOM](/enterprise_influxdb/v1.9/query_language/functions#bottom) | [bottom()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/bottom/) |
| [FIRST](/enterprise_influxdb/v1.9/query_language/functions#first) | [first()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/first/) |
| [LAST](/enterprise_influxdb/v1.9/query_language/functions#last) | [last()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/last/) |
| [MAX](/enterprise_influxdb/v1.9/query_language/functions#max) | [max()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/max/) |
| [MIN](/enterprise_influxdb/v1.9/query_language/functions#min) | [min()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/min/) |
| [PERCENTILE](/enterprise_influxdb/v1.9/query_language/functions#percentile) | [quantile()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/quantile/) |
| [SAMPLE](/enterprise_influxdb/v1.9/query_language/functions#sample) | [sample()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/sample/) |
| [TOP](/enterprise_influxdb/v1.9/query_language/functions#top) | [top()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/top/) |
| [ABS](/enterprise_influxdb/v1.9/query_language/functions#abs) | [math.abs()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/abs/) |
| [ACOS](/enterprise_influxdb/v1.9/query_language/functions#acos) | [math.acos()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/acos/) |
| [ASIN](/enterprise_influxdb/v1.9/query_language/functions#asin) | [math.asin()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/asin/) |
| [ATAN](/enterprise_influxdb/v1.9/query_language/functions#atan) | [math.atan()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/atan/) |
| [ATAN2](/enterprise_influxdb/v1.9/query_language/functions#atan2) | [math.atan2()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/atan2/) |
| [CEIL](/enterprise_influxdb/v1.9/query_language/functions#ceil) | [math.ceil()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/ceil/) |
| [COS](/enterprise_influxdb/v1.9/query_language/functions#cos) | [math.cos()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/cos/) |
| [CUMULATIVE_SUM](/enterprise_influxdb/v1.9/query_language/functions#cumulative-sum) | [cumulativeSum()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/cumulativesum/) |
| [DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#derivative) | [derivative()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/derivative/) |
| [DIFFERENCE](/enterprise_influxdb/v1.9/query_language/functions#difference) | [difference()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/difference/) |
| [ELAPSED](/enterprise_influxdb/v1.9/query_language/functions#elapsed) | [elapsed()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/elapsed/) |
| [EXP](/enterprise_influxdb/v1.9/query_language/functions#exp) | [math.exp()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/exp/) |
| [FLOOR](/enterprise_influxdb/v1.9/query_language/functions#floor) | [math.floor()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/floor/) |
| [HISTOGRAM](/enterprise_influxdb/v1.9/query_language/functions#histogram) | [histogram()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/histogram/) |
| [LN](/enterprise_influxdb/v1.9/query_language/functions#ln) | [math.log()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/log/) |
| [LOG](/enterprise_influxdb/v1.9/query_language/functions#log) | [math.logb()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/logb/) |
| [LOG2](/enterprise_influxdb/v1.9/query_language/functions#log2) | [math.log2()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/log2/) |
| [LOG10](/enterprise_influxdb/v1.9/query_language/functions/#log10) | [math.log10()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/log10/) |
| [MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#moving-average) | [movingAverage()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/movingaverage/) |
| [NON_NEGATIVE_DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#non-negative-derivative) | [derivative(nonNegative:true)](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/derivative/) |
| [NON_NEGATIVE_DIFFERENCE](/enterprise_influxdb/v1.9/query_language/functions#non-negative-difference) | [difference(nonNegative:true)](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/derivative/) |
| [POW](/enterprise_influxdb/v1.9/query_language/functions#pow) | [math.pow()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/pow/) |
| [ROUND](/enterprise_influxdb/v1.9/query_language/functions#round) | [math.round()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/round/) |
| [SIN](/enterprise_influxdb/v1.9/query_language/functions#sin) | [math.sin()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/sin/) |
| [SQRT](/enterprise_influxdb/v1.9/query_language/functions#sqrt) | [math.sqrt()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/sqrt/) |
| [TAN](/enterprise_influxdb/v1.9/query_language/functions#tan) | [math.tan()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/math/tan/) |
| [HOLT_WINTERS](/enterprise_influxdb/v1.9/query_language/functions#holt-winters) | [holtWinters()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/holtwinters/) |
| [CHANDE_MOMENTUM_OSCILLATOR](/enterprise_influxdb/v1.9/query_language/functions#chande-momentum-oscillator) | [chandeMomentumOscillator()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/chandemomentumoscillator/) |
| [EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#exponential-moving-average) | [exponentialMovingAverage()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/) |
| [DOUBLE_EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#double-exponential-moving-average) | [doubleEMA()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/doubleema/) |
| [KAUFMANS_EFFICIENCY_RATIO](/enterprise_influxdb/v1.9/query_language/functions#kaufmans-efficiency-ratio) | [kaufmansER()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/kaufmanser/) |
| [KAUFMANS_ADAPTIVE_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#kaufmans-adaptive-moving-average) | [kaufmansAMA()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/kaufmansama/) |
| [TRIPLE_EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#triple-exponential-moving-average) | [tripleEMA()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/tripleema/) |
| [TRIPLE_EXPONENTIAL_DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#triple-exponential-derivative) | [tripleExponentialDerivative()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/tripleexponentialderivative/) |
| [RELATIVE_STRENGTH_INDEX](/enterprise_influxdb/v1.9/query_language/functions#relative-strength-index) | [relativeStrengthIndex()](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/relativestrengthindex/) |
| InfluxQL | Flux Functions |
| :------------------------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [SELECT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-basic-select-statement) | [filter()](/{{< latest "flux" >}}/stdlib/universe/filter/) |
| [WHERE](/enterprise_influxdb/v1.9/query_language/explore-data/#the-where-clause) | [filter()](/{{< latest "flux" >}}/stdlib/universe/filter/), [range()](/{{< latest "flux" >}}/stdlib/universe/range/) |
| [GROUP BY](/enterprise_influxdb/v1.9/query_language/explore-data/#the-group-by-clause) | [group()](/{{< latest "flux" >}}/stdlib/universe/group/) |
| [INTO](/enterprise_influxdb/v1.9/query_language/explore-data/#the-into-clause) | [to()](/{{< latest "flux" >}}/stdlib/universe/to/) <span><a style="color:orange" href="#footnote">*</a></span> |
| [ORDER BY](/enterprise_influxdb/v1.9/query_language/explore-data/#order-by-time-desc) | [sort()](/{{< latest "flux" >}}/stdlib/universe/sort/) |
| [LIMIT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-limit-clause) | [limit()](/{{< latest "flux" >}}/stdlib/universe/limit/) |
| [SLIMIT](/enterprise_influxdb/v1.9/query_language/explore-data/#the-slimit-clause) | -- |
| [OFFSET](/enterprise_influxdb/v1.9/query_language/explore-data/#the-offset-clause) | -- |
| [SOFFSET](/enterprise_influxdb/v1.9/query_language/explore-data/#the-soffset-clause) | -- |
| [SHOW DATABASES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-databases) | [buckets()](/{{< latest "flux" >}}/stdlib/universe/buckets/) |
| [SHOW MEASUREMENTS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-measurements) | [v1.measurements](/{{< latest "flux" >}}/stdlib/influxdb-v1/measurements) |
| [SHOW FIELD KEYS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-field-keys) | [keys()](/{{< latest "flux" >}}/stdlib/universe/keys/) |
| [SHOW RETENTION POLICIES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-retention-policies) | [buckets()](/{{< latest "flux" >}}/stdlib/universe/buckets/) |
| [SHOW TAG KEYS](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-tag-keys) | [v1.tagKeys()](/{{< latest "flux" >}}/stdlib/influxdb-v1/tagkeys), [v1.measurementTagKeys()](/{{< latest "flux" >}}/stdlib/influxdb-v1/measurementtagkeys) |
| [SHOW TAG VALUES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-tag-values) | [v1.tagValues()](/{{< latest "flux" >}}/stdlib/influxdb-v1/tagvalues), [v1.measurementTagValues()](/{{< latest "flux" >}}/stdlib/influxdb-v1/measurementtagvalues) |
| [SHOW SERIES](/enterprise_influxdb/v1.9/query_language/explore-schema/#show-series) | -- |
| [CREATE DATABASE](/enterprise_influxdb/v1.9/query_language/manage-database/#create-database) | -- |
| [DROP DATABASE](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-a-database-with-drop-database) | -- |
| [DROP SERIES](/enterprise_influxdb/v1.9/query_language/manage-database/#drop-series-from-the-index-with-drop-series) | -- |
| [DELETE](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-series-with-delete) | -- |
| [DROP MEASUREMENT](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-measurements-with-drop-measurement) | -- |
| [DROP SHARD](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-a-shard-with-drop-shard) | -- |
| [CREATE RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#create-retention-policies-with-create-retention-policy) | -- |
| [ALTER RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#modify-retention-policies-with-alter-retention-policy) | -- |
| [DROP RETENTION POLICY](/enterprise_influxdb/v1.9/query_language/manage-database/#delete-retention-policies-with-drop-retention-policy) | -- |
| [COUNT](/enterprise_influxdb/v1.9/query_language/functions#count) | [count()](/{{< latest "flux" >}}/stdlib/universe/count/) |
| [DISTINCT](/enterprise_influxdb/v1.9/query_language/functions#distinct) | [distinct()](/{{< latest "flux" >}}/stdlib/universe/distinct/) |
| [INTEGRAL](/enterprise_influxdb/v1.9/query_language/functions#integral) | [integral()](/{{< latest "flux" >}}/stdlib/universe/integral/) |
| [MEAN](/enterprise_influxdb/v1.9/query_language/functions#mean) | [mean()](/{{< latest "flux" >}}/stdlib/universe/mean/) |
| [MEDIAN](/enterprise_influxdb/v1.9/query_language/functions#median) | [median()](/{{< latest "flux" >}}/stdlib/universe/median/) |
| [MODE](/enterprise_influxdb/v1.9/query_language/functions#mode) | [mode()](/{{< latest "flux" >}}/stdlib/universe/mode/) |
| [SPREAD](/enterprise_influxdb/v1.9/query_language/functions#spread) | [spread()](/{{< latest "flux" >}}/stdlib/universe/spread/) |
| [STDDEV](/enterprise_influxdb/v1.9/query_language/functions#stddev) | [stddev()](/{{< latest "flux" >}}/stdlib/universe/stddev/) |
| [SUM](/enterprise_influxdb/v1.9/query_language/functions#sum) | [sum()](/{{< latest "flux" >}}/stdlib/universe/sum/) |
| [BOTTOM](/enterprise_influxdb/v1.9/query_language/functions#bottom) | [bottom()](/{{< latest "flux" >}}/stdlib/universe/bottom/) |
| [FIRST](/enterprise_influxdb/v1.9/query_language/functions#first) | [first()](/{{< latest "flux" >}}/stdlib/universe/first/) |
| [LAST](/enterprise_influxdb/v1.9/query_language/functions#last) | [last()](/{{< latest "flux" >}}/stdlib/universe/last/) |
| [MAX](/enterprise_influxdb/v1.9/query_language/functions#max) | [max()](/{{< latest "flux" >}}/stdlib/universe/max/) |
| [MIN](/enterprise_influxdb/v1.9/query_language/functions#min) | [min()](/{{< latest "flux" >}}/stdlib/universe/min/) |
| [PERCENTILE](/enterprise_influxdb/v1.9/query_language/functions#percentile) | [quantile()](/{{< latest "flux" >}}/stdlib/universe/quantile/) |
| [SAMPLE](/enterprise_influxdb/v1.9/query_language/functions#sample) | [sample()](/{{< latest "flux" >}}/stdlib/universe/sample/) |
| [TOP](/enterprise_influxdb/v1.9/query_language/functions#top) | [top()](/{{< latest "flux" >}}/stdlib/universe/top/) |
| [ABS](/enterprise_influxdb/v1.9/query_language/functions#abs) | [math.abs()](/{{< latest "flux" >}}/stdlib/math/abs/) |
| [ACOS](/enterprise_influxdb/v1.9/query_language/functions#acos) | [math.acos()](/{{< latest "flux" >}}/stdlib/math/acos/) |
| [ASIN](/enterprise_influxdb/v1.9/query_language/functions#asin) | [math.asin()](/{{< latest "flux" >}}/stdlib/math/asin/) |
| [ATAN](/enterprise_influxdb/v1.9/query_language/functions#atan) | [math.atan()](/{{< latest "flux" >}}/stdlib/math/atan/) |
| [ATAN2](/enterprise_influxdb/v1.9/query_language/functions#atan2) | [math.atan2()](/{{< latest "flux" >}}/stdlib/math/atan2/) |
| [CEIL](/enterprise_influxdb/v1.9/query_language/functions#ceil) | [math.ceil()](/{{< latest "flux" >}}/stdlib/math/ceil/) |
| [COS](/enterprise_influxdb/v1.9/query_language/functions#cos) | [math.cos()](/{{< latest "flux" >}}/stdlib/math/cos/) |
| [CUMULATIVE_SUM](/enterprise_influxdb/v1.9/query_language/functions#cumulative-sum) | [cumulativeSum()](/{{< latest "flux" >}}/stdlib/universe/cumulativesum/) |
| [DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#derivative) | [derivative()](/{{< latest "flux" >}}/stdlib/universe/derivative/) |
| [DIFFERENCE](/enterprise_influxdb/v1.9/query_language/functions#difference) | [difference()](/{{< latest "flux" >}}/stdlib/universe/difference/) |
| [ELAPSED](/enterprise_influxdb/v1.9/query_language/functions#elapsed) | [elapsed()](/{{< latest "flux" >}}/stdlib/universe/elapsed/) |
| [EXP](/enterprise_influxdb/v1.9/query_language/functions#exp) | [math.exp()](/{{< latest "flux" >}}/stdlib/math/exp/) |
| [FLOOR](/enterprise_influxdb/v1.9/query_language/functions#floor) | [math.floor()](/{{< latest "flux" >}}/stdlib/math/floor/) |
| [HISTOGRAM](/enterprise_influxdb/v1.9/query_language/functions#histogram) | [histogram()](/{{< latest "flux" >}}/stdlib/universe/histogram/) |
| [LN](/enterprise_influxdb/v1.9/query_language/functions#ln) | [math.log()](/{{< latest "flux" >}}/stdlib/math/log/) |
| [LOG](/enterprise_influxdb/v1.9/query_language/functions#log) | [math.logb()](/{{< latest "flux" >}}/stdlib/math/logb/) |
| [LOG2](/enterprise_influxdb/v1.9/query_language/functions#log2) | [math.log2()](/{{< latest "flux" >}}/stdlib/math/log2/) |
| [LOG10](/enterprise_influxdb/v1.9/query_language/functions/#log10) | [math.log10()](/{{< latest "flux" >}}/stdlib/math/log10/) |
| [MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#moving-average) | [movingAverage()](/{{< latest "flux" >}}/stdlib/universe/movingaverage/) |
| [NON_NEGATIVE_DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#non-negative-derivative) | [derivative(nonNegative:true)](/{{< latest "flux" >}}/stdlib/universe/derivative/) |
| [NON_NEGATIVE_DIFFERENCE](/enterprise_influxdb/v1.9/query_language/functions#non-negative-difference) | [difference(nonNegative:true)](/{{< latest "flux" >}}/stdlib/universe/derivative/) |
| [POW](/enterprise_influxdb/v1.9/query_language/functions#pow) | [math.pow()](/{{< latest "flux" >}}/stdlib/math/pow/) |
| [ROUND](/enterprise_influxdb/v1.9/query_language/functions#round) | [math.round()](/{{< latest "flux" >}}/stdlib/math/round/) |
| [SIN](/enterprise_influxdb/v1.9/query_language/functions#sin) | [math.sin()](/{{< latest "flux" >}}/stdlib/math/sin/) |
| [SQRT](/enterprise_influxdb/v1.9/query_language/functions#sqrt) | [math.sqrt()](/{{< latest "flux" >}}/stdlib/math/sqrt/) |
| [TAN](/enterprise_influxdb/v1.9/query_language/functions#tan) | [math.tan()](/{{< latest "flux" >}}/stdlib/math/tan/) |
| [HOLT_WINTERS](/enterprise_influxdb/v1.9/query_language/functions#holt-winters) | [holtWinters()](/{{< latest "flux" >}}/stdlib/universe/holtwinters/) |
| [CHANDE_MOMENTUM_OSCILLATOR](/enterprise_influxdb/v1.9/query_language/functions#chande-momentum-oscillator) | [chandeMomentumOscillator()](/{{< latest "flux" >}}/stdlib/universe/chandemomentumoscillator/) |
| [EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#exponential-moving-average) | [exponentialMovingAverage()](/{{< latest "flux" >}}/stdlib/universe/exponentialmovingaverage/) |
| [DOUBLE_EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#double-exponential-moving-average) | [doubleEMA()](/{{< latest "flux" >}}/stdlib/universe/doubleema/) |
| [KAUFMANS_EFFICIENCY_RATIO](/enterprise_influxdb/v1.9/query_language/functions#kaufmans-efficiency-ratio) | [kaufmansER()](/{{< latest "flux" >}}/stdlib/universe/kaufmanser/) |
| [KAUFMANS_ADAPTIVE_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#kaufmans-adaptive-moving-average) | [kaufmansAMA()](/{{< latest "flux" >}}/stdlib/universe/kaufmansama/) |
| [TRIPLE_EXPONENTIAL_MOVING_AVERAGE](/enterprise_influxdb/v1.9/query_language/functions#triple-exponential-moving-average) | [tripleEMA()](/{{< latest "flux" >}}/stdlib/universe/tripleema/) |
| [TRIPLE_EXPONENTIAL_DERIVATIVE](/enterprise_influxdb/v1.9/query_language/functions#triple-exponential-derivative) | [tripleExponentialDerivative()](/{{< latest "flux" >}}/stdlib/universe/tripleexponentialderivative/) |
| [RELATIVE_STRENGTH_INDEX](/enterprise_influxdb/v1.9/query_language/functions#relative-strength-index) | [relativeStrengthIndex()](/{{< latest "flux" >}}/stdlib/universe/relativestrengthindex/) |
_<span style="font-size:.9rem" id="footnote"><span style="color:orange">*</span> The <code>to()</code> function only writes to InfluxDB 2.0.</span>_

View File

@ -53,7 +53,7 @@ A **bucket** is a named location where data is stored that has a retention polic
It's similar to an InfluxDB v1.x "database," but is a combination of both a database and a retention policy.
When using multiple retention policies, each retention policy is treated as is its own bucket.
Flux's [`from()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/from), which defines an InfluxDB data source, requires a `bucket` parameter.
Flux's [`from()` function](/{{< latest "flux" >}}/stdlib/universe/from), which defines an InfluxDB data source, requires a `bucket` parameter.
When using Flux with InfluxDB v1.x, use the following bucket naming convention which combines
the database name and retention policy into a single bucket name:

View File

@ -24,7 +24,7 @@ Every Flux query needs the following:
## 1. Define your data source
Flux's [`from()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/from) function defines an InfluxDB data source.
Flux's [`from()`](/{{< latest "flux" >}}/stdlib/universe/from) function defines an InfluxDB data source.
It requires a [`bucket`](/enterprise_influxdb/v1.9/flux/get-started/#buckets) parameter.
For this example, use `telegraf/autogen`, a combination of the default database and retention policy provided by the TICK stack.
@ -37,11 +37,11 @@ Flux requires a time range when querying time series data.
"Unbounded" queries are very resource-intensive and as a protective measure,
Flux will not query the database without a specified range.
Use the pipe-forward operator (`|>`) to pipe data from your data source into the [`range()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/range)
Use the pipe-forward operator (`|>`) to pipe data from your data source into the [`range()`](/{{< latest "flux" >}}/stdlib/universe/range)
function, which specifies a time range for your query.
It accepts two properties: `start` and `stop`.
Ranges can be **relative** using negative [durations](/{{< latest "influxdb" "v2" >}}/reference/flux/language/lexical-elements#duration-literals)
or **absolute** using [timestamps](/{{< latest "influxdb" "v2" >}}/reference/flux/language/lexical-elements#date-and-time-literals).
Ranges can be **relative** using negative [durations](/{{< latest "flux" >}}/spec/lexical-elements#duration-literals)
or **absolute** using [timestamps](/{{< latest "flux" >}}/spec/lexical-elements#date-and-time-literals).
###### Example relative time ranges
```js

View File

@ -16,7 +16,7 @@ When [querying data from InfluxDB](/enterprise_influxdb/v1.9/flux/get-started/qu
you often need to transform that data in some way.
Common examples are aggregating data into averages, downsampling data, etc.
This guide demonstrates using [Flux functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib) to transform your data.
This guide demonstrates using [Flux functions](/{{< latest "flux" >}}/stdlib/) to transform your data.
It walks through creating a Flux script that partitions data into windows of time,
averages the `_value`s in each window, and outputs the averages as a new table.
@ -39,13 +39,13 @@ from(bucket:"telegraf/autogen")
## Flux functions
Flux provides a number of functions that perform specific operations, transformations, and tasks.
You can also [create custom functions](/{{< latest "influxdb" "v2" >}}/query-data/flux/custom-functions) in your Flux queries.
_Functions are covered in detail in the [Flux functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib) documentation._
_Functions are covered in detail in the [Flux standard library](/{{< latest "flux" >}}/stdlib/) documentation._
A common type of function used when transforming data queried from InfluxDB is an aggregate function.
Aggregate functions take a set of `_value`s in a table, aggregate them, and transform
them into a new value.
This example uses the [`mean()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/mean)
This example uses the [`mean()` function](/{{< latest "flux" >}}/stdlib/universe/mean)
to average values within time windows.
> The following example walks through the steps required to window and aggregate data,
@ -53,12 +53,12 @@ to average values within time windows.
> It's just good to understand the steps in the process.
## Window your data
Flux's [`window()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/window) partitions records based on a time value.
Flux's [`window()` function](/{{< latest "flux" >}}/stdlib/universe/window) partitions records based on a time value.
Use the `every` parameter to define a duration of time for each window.
{{% note %}}
#### Calendar months and years
`every` supports all [valid duration units](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#duration-types),
`every` supports all [valid duration units](/{{< latest "flux" >}}/spec/types/#duration-types),
including **calendar months (`1mo`)** and **years (`1y`)**.
{{% /note %}}
@ -82,7 +82,7 @@ When visualized, each table is assigned a unique color.
## Aggregate windowed data
Flux aggregate functions take the `_value`s in each table and aggregate them in some way.
Use the [`mean()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/mean) to average the `_value`s of each table.
Use the [`mean()` function](/{{< latest "flux" >}}/stdlib/universe/mean) to average the `_value`s of each table.
```js
from(bucket:"telegraf/autogen")
@ -108,7 +108,7 @@ Aggregate functions don't infer what time should be used for the aggregate value
Therefore the `_time` column is dropped.
A `_time` column is required in the [next operation](#unwindow-aggregate-tables).
To add one, use the [`duplicate()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/duplicate)
To add one, use the [`duplicate()` function](/{{< latest "flux" >}}/stdlib/universe/duplicate)
to duplicate the `_stop` column as the `_time` column for each windowed table.
```js
@ -153,7 +153,7 @@ process helps to understand how data changes "shape" as it is passed through eac
Flux provides (and allows you to create) "helper" functions that abstract many of these steps.
The same operation performed in this guide can be accomplished using the
[`aggregateWindow()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow).
[`aggregateWindow()` function](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow).
```js
from(bucket:"telegraf/autogen")

View File

@ -20,12 +20,12 @@ Use `map()` to re-map values in the row and calculate a percentage.
**To calculate percentages**
1. Use [`from()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/from/),
[`range()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/range/) and
[`filter()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/) to query operands.
1. Use [`from()`](/{{< latest "flux" >}}/stdlib/built-in/inputs/from/),
[`range()`](/{{< latest "flux" >}}/stdlib/universe/range/) and
[`filter()`](/{{< latest "flux" >}}/stdlib/universe/filter/) to query operands.
2. Use [`pivot()` or `join()`](/enterprise_influxdb/v1.9/flux/guides/mathematic-operations/#pivot-vs-join)
to align operand values into rows.
3. Use [`map()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/)
3. Use [`map()`](/{{< latest "flux" >}}/stdlib/universe/map/)
to divide the numerator operand value by the denominator operand value and multiply by 100.
{{% note %}}

View File

@ -33,9 +33,9 @@ Conditional expressions are most useful in the following contexts:
- When defining variables.
- When using functions that operate on a single row at a time (
[`filter()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/),
[`map()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/),
[`reduce()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/reduce) ).
[`filter()`](/{{< latest "flux" >}}/stdlib/universe/filter/),
[`map()`](/{{< latest "flux" >}}/stdlib/universe/map/),
[`reduce()`](/{{< latest "flux" >}}/stdlib/universe/reduce) ).
## Evaluating conditional expressions
@ -93,7 +93,7 @@ from(bucket: "telegraf/autogen")
```
### Conditionally transform column values with map()
The following example uses the [`map()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/)
The following example uses the [`map()` function](/{{< latest "flux" >}}/stdlib/universe/map/)
to conditionally transform column values.
It sets the `level` column to a specific string based on `_value` column.
@ -140,8 +140,8 @@ from(bucket: "telegraf/autogen")
{{< /code-tabs-wrapper >}}
### Conditionally increment a count with reduce()
The following example uses the [`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
and [`reduce()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/reduce/)
The following example uses the [`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/)
and [`reduce()`](/{{< latest "flux" >}}/stdlib/universe/reduce/)
functions to count the number of records in every five minute window that exceed a defined threshold.
{{< code-tabs-wrapper >}}

View File

@ -14,7 +14,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/cumulativesum/
v2: /influxdb/v2.0/query-data/flux/cumulativesum/
---
Use the [`cumulativeSum()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/cumulativesum/)
Use the [`cumulativeSum()` function](/{{< latest "flux" >}}/stdlib/universe/cumulativesum/)
to calculate a running total of values.
`cumulativeSum` sums the values of subsequent records and returns each row updated with the summed total.
@ -52,7 +52,7 @@ data
```
## Use cumulativeSum() with aggregateWindow()
[`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
[`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/)
segments data into windows of time, aggregates data in each window into a single
point, then removes the time-based segmentation.
It is primarily used to downsample data.

View File

@ -39,9 +39,9 @@ If you're just getting started with Flux queries, check out the following:
- [Execute queries](/enterprise_influxdb/v1.9/flux/guides/execute-queries/) to discover a variety of ways to run your queries.
Use `exists` with row functions (
[`filter()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/),
[`map()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/),
[`reduce()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/reduce/))
[`filter()`](/{{< latest "flux" >}}/stdlib/universe/filter/),
[`map()`](/{{< latest "flux" >}}/stdlib/universe/map/),
[`reduce()`](/{{< latest "flux" >}}/stdlib/universe/reduce/))
to check if a row includes a column or if the value for that column is `null`.
#### Filter null values

View File

@ -14,7 +14,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/fill/
v2: /influxdb/v2.0/query-data/flux/fill/
---
Use the [`fill()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/fill/)
Use the [`fill()` function](/{{< latest "flux" >}}/stdlib/universe/fill/)
to replace _null_ values with:
- [the previous non-null value](#fill-with-the-previous-value)
@ -78,8 +78,8 @@ data
## Fill with a specified value
To fill _null_ values with a specified value, use the `value` parameter to specify the fill value.
_The fill value must match the [data type](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#basic-types)
of the [column](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/fill/#column)._
_The fill value must match the [data type](/{{< latest "flux" >}}/language/types/#basic-types)
of the [column](/{{< latest "flux" >}}/stdlib/universe/fill/#column)._
```js
data

View File

@ -14,8 +14,8 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/first-last/
v2: /influxdb/v2.0/query-data/flux/first-last/
---
Use the [`first()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/first/) or
[`last()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/last/) functions
Use the [`first()`](/{{< latest "flux" >}}/stdlib/universe/first/) or
[`last()`](/{{< latest "flux" >}}/stdlib/universe/last/) functions
to return the first or last record in an input table.
```js
@ -30,7 +30,7 @@ data
{{% note %}}
By default, InfluxDB returns results sorted by time, however you can use the
[`sort()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/sort/)
[`sort()` function](/{{< latest "flux" >}}/stdlib/universe/sort/)
to change how results are sorted.
`first()` and `last()` respect the sort order of input data and return records
based on the order they are received in.
@ -90,7 +90,7 @@ based on the order they are received in.
{{< /flex >}}
## Use first() or last() with aggregateWindow()
Use `first()` and `last()` with [`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
Use `first()` and `last()` with [`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/)
to select the first or last records in time-based groups.
`aggregateWindow()` segments data into windows of time, aggregates data in each window into a single
point using aggregate or selector functions, and then removes the time-based segmentation.

View File

@ -20,12 +20,12 @@ list_code_example: |
```
---
Use the [Flux Geo package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo) to
Use the [Flux Geo package](/{{< latest "flux" >}}/stdlib/experimental/geo) to
filter geo-temporal data and group by geographic location or track.
{{% warn %}}
The Geo package is experimental and subject to change at any time.
By using it, you agree to the [risks of experimental functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/#use-experimental-functions-at-your-own-risk).
By using it, you agree to the [risks of experimental functions](/{{< latest "flux" >}}/stdlib/experimental/#experimental-functions-are-subject-to-change).
{{% /warn %}}
**To work with geo-temporal data:**
@ -52,10 +52,10 @@ Many of the examples in this section use a `sampleGeoData` variable that represe
a sample set of geo-temporal data.
The [Bird Migration Sample Data](https://github.com/influxdata/influxdb2-sample-data/tree/master/bird-migration-data)
available on GitHub provides sample geo-temporal data that meets the
[requirements of the Flux Geo package](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/#geo-schema-requirements).
[requirements of the Flux Geo package](/{{< latest "flux" >}}/stdlib/experimental/geo/#geo-schema-requirements).
### Load annotated CSV sample data
Use the [experimental `csv.from()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/csv/from/)
Use the [experimental `csv.from()` function](/{{< latest "flux" >}}/stdlib/experimental/csv/from/)
to load the sample bird migration annotated CSV data from GitHub:
```js
@ -68,8 +68,8 @@ sampleGeoData = csv.from(
{{% note %}}
`csv.from(url: ...)` downloads sample data each time you execute the query **(~1.3 MB)**.
If bandwidth is a concern, use the [`to()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/outputs/to/)
to write the data to a bucket, and then query the bucket with [`from()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/from/).
If bandwidth is a concern, use the [`to()` function](/{{< latest "flux" >}}/stdlib/built-in/outputs/to/)
to write the data to a bucket, and then query the bucket with [`from()`](/{{< latest "flux" >}}/stdlib/built-in/inputs/from/).
{{% /note %}}
### Write sample data to InfluxDB with line protocol

View File

@ -8,8 +8,8 @@ menu:
parent: Geo-temporal data
weight: 302
related:
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/filterrows/
- /{{< latest "flux" >}}/stdlib/experimental/geo/
- /{{< latest "flux" >}}/stdlib/experimental/geo/filterrows/
canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/geo/filter-by-region/
v2: /influxdb/v2.0/query-data/flux/geo/filter-by-region/
list_code_example: |
@ -24,7 +24,7 @@ list_code_example: |
```
---
Use the [`geo.filterRows` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/filterrows/)
Use the [`geo.filterRows` function](/{{< latest "flux" >}}/stdlib/experimental/geo/filterrows/)
to filter geo-temporal data by geographic region:
1. [Define a geographic region](#define-a-geographic-region)

View File

@ -8,9 +8,9 @@ menu:
parent: Geo-temporal data
weight: 302
related:
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/groupbyarea/
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/astracks/
- /{{< latest "flux" >}}/stdlib/experimental/geo/
- /{{< latest "flux" >}}/stdlib/experimental/geo/groupbyarea/
- /{{< latest "flux" >}}/stdlib/experimental/geo/astracks/
canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/geo/group-geo-data/
v2: /influxdb/v2.0/query-data/flux/geo/group-geo-data/
list_code_example: |
@ -30,7 +30,7 @@ to group data into tracks or routes.
- [Group data into tracks or routes](#group-data-by-track-or-route)
### Group data by area
Use the [`geo.groupByArea()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/groupbyarea/)
Use the [`geo.groupByArea()` function](/{{< latest "flux" >}}/stdlib/experimental/geo/groupbyarea/)
to group geo-temporal data points by geographic area.
Areas are determined by [S2 grid cells](https://s2geometry.io/devguide/s2cell_hierarchy.html#s2cellid-numbering)
@ -53,7 +53,7 @@ sampleGeoData
```
### Group data by track or route
Use [`geo.asTracks()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/astracks/)
Use [`geo.asTracks()` function](/{{< latest "flux" >}}/stdlib/experimental/geo/astracks/)
to group data points into tracks or routes and order them by time or other columns.
Data must contain a unique identifier for each track. For example: `id` or `tid`.

View File

@ -9,8 +9,8 @@ menu:
parent: Geo-temporal data
weight: 301
related:
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/
- /{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/shapedata/
- /{{< latest "flux" >}}/stdlib/experimental/geo/
- /{{< latest "flux" >}}/stdlib/experimental/geo/shapedata/
canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/geo/shape-geo-data/
v2: /influxdb/v2.0/query-data/flux/geo/shape-geo-data/
list_code_example: |
@ -31,7 +31,7 @@ Functions in the Geo package require the following data schema:
## Shape geo-temporal data
If your data already contains latitude and longitude fields, use the
[`geo.shapeData()`function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/shapedata/)
[`geo.shapeData()`function](/{{< latest "flux" >}}/stdlib/experimental/geo/shapedata/)
to rename the fields to match the requirements of the Geo package, pivot the data
into row-wise sets, and generate S2 cell ID tokens for each point.
@ -99,9 +99,9 @@ Library to generate `s2_cell_id` tags. For example:
- **JavaScript:** [s2.cellid.toToken()](https://github.com/mapbox/node-s2/blob/master/API.md#cellidtotoken---string)
### Generate S2 cell ID tokens with Flux
Use the [`geo.s2CellIDToken()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/s2cellidtoken/)
Use the [`geo.s2CellIDToken()` function](/{{< latest "flux" >}}/stdlib/experimental/geo/s2cellidtoken/)
with existing longitude (`lon`) and latitude (`lat`) field values to generate and add the S2 cell ID token.
First, use the [`geo.toRows()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/torows/)
First, use the [`geo.toRows()` function](/{{< latest "flux" >}}/stdlib/experimental/geo/torows/)
to pivot **lat** and **lon** fields into row-wise sets:
```js
@ -117,6 +117,6 @@ from(bucket: "example-bucket")
```
{{% note %}}
The [`geo.shapeData()`function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/geo/shapedata/)
The [`geo.shapeData()`function](/{{< latest "flux" >}}/stdlib/experimental/geo/shapedata/)
generates S2 cell ID tokens as well.
{{% /note %}}

View File

@ -37,7 +37,7 @@ Understanding how modifying group keys shapes output data is key to successfully
grouping and transforming data into your desired output.
## group() Function
Flux's [`group()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/group) defines the
Flux's [`group()` function](/{{< latest "flux" >}}/stdlib/universe/group) defines the
group key for output tables, i.e. grouping records based on values for specific columns.
###### group() example

View File

@ -17,7 +17,7 @@ Histograms provide valuable insight into the distribution of your data.
This guide walks through using Flux's `histogram()` function to transform your data into a **cumulative histogram**.
## histogram() function
The [`histogram()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/histogram) approximates the
The [`histogram()` function](/{{< latest "flux" >}}/stdlib/universe/histogram) approximates the
cumulative distribution of a dataset by counting data frequencies for a list of "bins."
A **bin** is simply a range in which a data point falls.
All data points that are less than or equal to the bound are counted in the bin.
@ -42,7 +42,7 @@ Flux provides two helper functions for generating histogram bins.
Each generates and outputs an array of floats designed to be used in the `histogram()` function's `bins` parameter.
### linearBins()
The [`linearBins()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/misc/linearbins) generates a list of linearly separated floats.
The [`linearBins()` function](/{{< latest "flux" >}}/stdlib/built-in/misc/linearbins) generates a list of linearly separated floats.
```js
linearBins(start: 0.0, width: 10.0, count: 10)
@ -51,7 +51,7 @@ linearBins(start: 0.0, width: 10.0, count: 10)
```
### logarithmicBins()
The [`logarithmicBins()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/misc/logarithmicbins) generates a list of exponentially separated floats.
The [`logarithmicBins()` function](/{{< latest "flux" >}}/stdlib/built-in/misc/logarithmicbins) generates a list of exponentially separated floats.
```js
logarithmicBins(start: 1.0, factor: 2.0, count: 10, infinty: true)

View File

@ -16,7 +16,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/increase/
v2: /influxdb/v2.0/query-data/flux/increase/
---
Use the [`increase()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/increase/)
Use the [`increase()` function](/{{< latest "flux" >}}/stdlib/universe/increase/)
to track increases across multiple columns in a table.
This function is especially useful when tracking changes in counter values that
wrap over time or periodically reset.

View File

@ -13,7 +13,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/join/
v2: /influxdb/v2.0/query-data/flux/join/
---
The [`join()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/join) merges two or more
The [`join()` function](/{{< latest "flux" >}}/stdlib/universe/join) merges two or more
input streams, whose values are equal on a set of common columns, into a single output stream.
Flux allows you to join on any columns common between two data streams and opens the door
for operations such as cross-measurement joins and math across measurements.
@ -213,7 +213,7 @@ These represent the columns with values unique to the two input tables.
## Calculate and create a new table
With the two streams of data joined into a single table, use the
[`map()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map)
[`map()` function](/{{< latest "flux" >}}/stdlib/universe/map)
to build a new table by mapping the existing `_time` column to a new `_time`
column and dividing `_value_mem` by `_value_proc` and mapping it to a
new `_value` column.

View File

@ -35,7 +35,7 @@ If you're just getting started with Flux queries, check out the following:
- [RFC3339 to Unix nanosecond](#rfc3339-to-unix-nanosecond)
### Unix nanosecond to RFC3339
Use the [`time()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/time/)
Use the [`time()` function](/{{< latest "flux" >}}/stdlib/universe/type-conversions/time/)
to convert a [Unix **nanosecond** timestamp](/{{< latest "influxdb" "v2" >}}/reference/glossary/#unix-timestamp)
to an [RFC3339 timestamp](/{{< latest "influxdb" "v2" >}}/reference/glossary/#rfc3339-timestamp).
@ -45,7 +45,7 @@ time(v: 1568808000000000000)
```
### RFC3339 to Unix nanosecond
Use the [`uint()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/uint/)
Use the [`uint()` function](/{{< latest "flux" >}}/stdlib/universe/type-conversions/uint/)
to convert an RFC3339 timestamp to a Unix nanosecond timestamp.
```js
@ -54,7 +54,7 @@ uint(v: 2019-09-18T12:00:00.000000000Z)
```
## Calculate the duration between two timestamps
Flux doesn't support mathematical operations using [time type](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#time-types) values.
Flux doesn't support mathematical operations using [time type](/{{< latest "flux" >}}/language/types/#time-types) values.
To calculate the duration between two timestamps:
1. Use the `uint()` function to convert each timestamp to a Unix nanosecond timestamp.
@ -71,7 +71,7 @@ duration(v: time2 - time1)
{{% note %}}
Flux doesn't support duration column types.
To store a duration in a column, use the [`string()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/string/)
To store a duration in a column, use the [`string()` function](/{{< latest "flux" >}}/stdlib/universe/type-conversions/string/)
to convert the duration to a string.
{{% /note %}}
@ -80,7 +80,7 @@ to convert the duration to a string.
- [Current system time](#current-system-time)
### Current UTC time
Use the [`now()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/misc/now/) to
Use the [`now()` function](/{{< latest "flux" >}}/stdlib/built-in/misc/now/) to
return the current UTC time in RFC3339 format.
```js
@ -93,7 +93,7 @@ return the same value.
{{% /note %}}
### Current system time
Import the `system` package and use the [`system.time()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/system/time/)
Import the `system` package and use the [`system.time()` function](/{{< latest "flux" >}}/stdlib/system/time/)
to return the current system time of the host machine in RFC3339 format.
```js
@ -109,9 +109,9 @@ in a Flux script returns a unique value.
## Normalize irregular timestamps
To normalize irregular timestamps, truncate all `_time` values to a specified unit
with the [`truncateTimeColumn()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/truncatetimecolumn/).
This is useful in [`join()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/join/)
and [`pivot()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/pivot/)
with the [`truncateTimeColumn()` function](/{{< latest "flux" >}}/stdlib/universe/truncatetimecolumn/).
This is useful in [`join()`](/{{< latest "flux" >}}/stdlib/universe/join/)
and [`pivot()`](/{{< latest "flux" >}}/stdlib/universe/pivot/)
operations where points should align by time, but timestamps vary slightly.
```js
@ -149,12 +149,12 @@ data
- [Subtract a duration from a timestamp](#subtract-a-duration-from-a-timestamp)
### Add a duration to a timestamp
The [`experimental.addDuration()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/addduration/)
The [`experimental.addDuration()` function](/{{< latest "flux" >}}/stdlib/experimental/addduration/)
adds a duration to a specified time and returns the resulting time.
{{% warn %}}
By using `experimental.addDuration()`, you accept the
[risks of experimental functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/#use-experimental-functions-at-your-own-risk).
[risks of experimental functions](/{{< latest "flux" >}}/stdlib/experimental/#experimental-functions-are-subject-to-change).
{{% /warn %}}
```js
@ -169,12 +169,12 @@ experimental.addDuration(
```
### Subtract a duration from a timestamp
The [`experimental.subDuration()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/subduration/)
The [`experimental.subDuration()` function](/{{< latest "flux" >}}/stdlib/experimental/subduration/)
subtracts a duration from a specified time and returns the resulting time.
{{% warn %}}
By using `experimental.subDuration()`, you accept the
[risks of experimental functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/#use-experimental-functions-at-your-own-risk).
[risks of experimental functions](/{{< latest "flux" >}}/stdlib/experimental/#experimental-functions-are-subject-to-change).
{{% /warn %}}
```js

View File

@ -15,7 +15,7 @@ v2: /influxdb/v2.0/query-data/flux/mathematic-operations/
---
Flux supports mathematic expressions in data transformations.
This article describes how to use [Flux arithmetic operators](/{{< latest "influxdb" "v2" >}}/reference/flux/language/operators/#arithmetic-operators)
This article describes how to use [Flux arithmetic operators](/{{< latest "flux" >}}/language/operators/#arithmetic-operators)
to "map" over data and transform values using mathematic operations.
If you're just getting started with Flux queries, check out the following:
@ -48,7 +48,7 @@ Otherwise, you will get an error similar to:
Error: type error: float != int
```
To convert operands to the same type, use [type-conversion functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/)
To convert operands to the same type, use [type-conversion functions](/{{< latest "flux" >}}/stdlib/universe/type-conversions/)
or manually format operands.
The operand data type determines the output data type.
For example:
@ -91,7 +91,7 @@ To transform multiple values in an input stream, your function needs to:
- [Handle piped-forward data](/{{< latest "influxdb" "v2" >}}/query-data/flux/custom-functions/#functions-that-manipulate-piped-forward-data).
- Each operand necessary for the calculation exists in each row _(see [Pivot vs join](#pivot-vs-join) below)_.
- Use the [`map()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map) to iterate over each row.
- Use the [`map()` function](/{{< latest "flux" >}}/stdlib/universe/map) to iterate over each row.
The example `multiplyByX()` function below includes:
@ -155,7 +155,7 @@ data
#### Include partial gigabytes
Because the original metric (bytes) is an integer, the output of the operation is an integer and does not include partial GBs.
To calculate partial GBs, convert the `_value` column and its values to floats using the
[`float()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/type-conversions/float)
[`float()` function](/{{< latest "flux" >}}/stdlib/universe/type-conversions/float)
and format the denominator in the division operation as a float.
```js

View File

@ -14,7 +14,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/median/
v2: /influxdb/v2.0/query-data/flux/median/
---
Use the [`median()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/median/)
Use the [`median()` function](/{{< latest "flux" >}}/stdlib/universe/median/)
to return a value representing the `0.5` quantile (50th percentile) or median of input data.
## Select a method for calculating the median
@ -129,13 +129,13 @@ data
```
## Use median() with aggregateWindow()
[`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
[`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/)
segments data into windows of time, aggregates data in each window into a single
point, and then removes the time-based segmentation.
It is primarily used to downsample data.
To specify the [median calculation method](#select-a-method-for-calculating-the-median) in `aggregateWindow()`, use the
[full function syntax](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function):
[full function syntax](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/#specify-parameters-of-the-aggregate-function):
```js
data

View File

@ -24,7 +24,7 @@ If you're just getting started with Flux queries, check out the following:
## Find how long a state persists
1. Use the [`stateDuration()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/stateduration/) function to calculate how long a column value has remained the same value (or state). Include the following information:
1. Use the [`stateDuration()`](/{{< latest "flux" >}}/stdlib/universe/stateduration/) function to calculate how long a column value has remained the same value (or state). Include the following information:
- **Column to search:** any tag key, tag value, field key, field value, or measurement.
- **Value:** the value (or state) to search for in the specified column.

View File

@ -14,8 +14,8 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/moving-average/
v2: /influxdb/v2.0/query-data/flux/moving-average/
---
Use the [`movingAverage()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/movingaverage/)
or [`timedMovingAverage()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/)
Use the [`movingAverage()`](/{{< latest "flux" >}}/stdlib/universe/movingaverage/)
or [`timedMovingAverage()`](/{{< latest "flux" >}}/stdlib/universe/timedmovingaverage/)
functions to return the moving average of data.
```js

View File

@ -15,7 +15,7 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/percentile-quantile/
v2: /influxdb/v2.0/query-data/flux/percentile-quantile/
---
Use the [`quantile()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/quantile/)
Use the [`quantile()` function](/{{< latest "flux" >}}/stdlib/universe/quantile/)
to return a value representing the `q` quantile or percentile of input data.
## Percentile versus quantile
@ -144,13 +144,13 @@ data
```
## Use quantile() with aggregateWindow()
[`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/)
[`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/)
segments data into windows of time, aggregates data in each window into a single
point, and then removes the time-based segmentation.
It is primarily used to downsample data.
To specify the [quantile calculation method](#select-a-method-for-calculating-the-quantile) in
`aggregateWindow()`, use the [full function syntax](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow/#specify-parameters-of-the-aggregate-function):
`aggregateWindow()`, use the [full function syntax](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow/#specify-parameters-of-the-aggregate-function):
```js
data

View File

@ -23,7 +23,7 @@ list_code_example: |
```
---
Use the [`filter()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/filter/)
Use the [`filter()` function](/{{< latest "flux" >}}/stdlib/universe/filter/)
to query data based on fields, tags, or any other column value.
`filter()` performs operations similar to the `SELECT` statement and the `WHERE`
clause in InfluxQL and other SQL-like query languages.
@ -44,7 +44,7 @@ The `fn` predicate function requires an `r` argument, which represents each row
as `filter()` iterates over input data.
Key-value pairs in the row record represent columns and their values.
Use **dot notation** or **bracket notation** to reference specific column values in the predicate function.
Use [logical operators](/{{< latest "influxdb" "v2" >}}/reference/flux/language/operators/#logical-operators)
Use [logical operators](/{{< latest "flux" >}}/language/operators/#logical-operators)
to chain multiple predicate expressions together.
```js
@ -59,8 +59,8 @@ r = {foo: "bar", baz: "quz"}
```
## Filter by fields and tags
The combination of [`from()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/inputs/from),
[`range()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/range),
The combination of [`from()`](/{{< latest "flux" >}}/stdlib/built-in/inputs/from),
[`range()`](/{{< latest "flux" >}}/stdlib/universe/range),
and `filter()` represent the most basic Flux query:
1. Use `from()` to define your [bucket](/enterprise_influxdb/v1.9/flux/get-started/#buckets).

View File

@ -18,9 +18,9 @@ v2: /influxdb/v2.0/query-data/flux/rate/
---
Use the [`derivative()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/derivative/)
Use the [`derivative()` function](/{{< latest "flux" >}}/stdlib/universe/derivative/)
to calculate the rate of change between subsequent values or the
[`aggregate.rate()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/aggregate/rate/)
[`aggregate.rate()` function](/{{< latest "flux" >}}/stdlib/experimental/aggregate/rate/)
to calculate the average rate of change per window of time.
If time between points varies, these functions normalize points to a common time interval
making values easily comparable.
@ -29,7 +29,7 @@ making values easily comparable.
- [Average rate of change per window of time](#average-rate-of-change-per-window-of-time)
## Rate of change between subsequent values
Use the [`derivative()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/derivative/)
Use the [`derivative()` function](/{{< latest "flux" >}}/stdlib/universe/derivative/)
to calculate the rate of change per unit of time between subsequent _non-null_ values.
```js
@ -38,7 +38,7 @@ data
```
By default, `derivative()` returns only positive derivative values and replaces negative values with _null_.
Cacluated values are returned as [floats](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#numeric-types).
Cacluated values are returned as [floats](/{{< latest "flux" >}}/language/types/#numeric-types).
{{< flex >}}
@ -115,7 +115,7 @@ include negative values.
## Average rate of change per window of time
Use the [`aggregate.rate()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/experimental/aggregate/rate/)
Use the [`aggregate.rate()` function](/{{< latest "flux" >}}/stdlib/experimental/aggregate/rate/)
to calculate the average rate of change per window of time.
```js
@ -129,7 +129,7 @@ data
)
```
`aggregate.rate()` returns the average rate of change (as a [float](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#numeric-types))
`aggregate.rate()` returns the average rate of change (as a [float](/{{< latest "flux" >}}/language/types/#numeric-types))
per `unit` for time intervals defined by `every`.
Negative values are replaced with _null_.

View File

@ -23,7 +23,7 @@ list_code_example: |
```
---
Use Flux [stream and table functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/stream-table/)
Use Flux [stream and table functions](/{{< latest "flux" >}}/stdlib/universe/stream-table/)
to extract scalar values from Flux query output.
This lets you, for example, dynamically set variables using query results.
@ -38,7 +38,7 @@ _The samples on this page use the [sample data provided below](#sample-data)._
{{% warn %}}
#### Current limitations
- The InfluxDB user interface (UI) does not currently support raw scalar output.
Use [`map()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/) to add
Use [`map()`](/{{< latest "flux" >}}/stdlib/universe/map/) to add
scalar values to output data.
- The [Flux REPL](/enterprise_influxdb/v1.9/flux/guides/execute-queries/#influx-cli) does not currently support
Flux stream and table functions (also known as "dynamic queries").
@ -56,7 +56,7 @@ If query results include only one table, it is still formatted as a stream of ta
You still must extract that table from the stream.
{{% /note %}}
Use [`tableFind()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/stream-table/tablefind/)
Use [`tableFind()`](/{{< latest "flux" >}}/stdlib/universe/stream-table/tablefind/)
to extract the **first** table whose [group key](/enterprise_influxdb/v1.9/flux/get-started/#group-keys)
values match the `fn` **predicate function**.
The predicate function requires a `key` record, which represents the group key of
@ -89,7 +89,7 @@ of tables piped-forward into `tableFind()`.
{{% /note %}}
## Extract a column from the table
Use the [`getColumn()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/stream-table/getcolumn/)
Use the [`getColumn()` function](/{{< latest "flux" >}}/stdlib/universe/stream-table/getcolumn/)
to output an array of values from a specific column in the extracted table.
@ -129,7 +129,7 @@ SFOTemps[2]
```
## Extract a row from the table
Use the [`getRecord()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/stream-table/getrecord/)
Use the [`getRecord()` function](/{{< latest "flux" >}}/stdlib/universe/stream-table/getrecord/)
to output data from a single row in the extracted table.
Specify the index of the row to output using the `idx` parameter.
The function outputs a record with key-value pairs for each column.
@ -232,7 +232,7 @@ The temperature was ${string(v: lastReported._value)}°F."
The following sample data set represents fictional temperature metrics collected
from three locations.
It's formatted in [annotated CSV](https://v2.docs.influxdata.com/v2.0/reference/syntax/annotated-csv/) and imported
into the Flux query using the [`csv.from()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/csv/from/).
into the Flux query using the [`csv.from()` function](/{{< latest "flux" >}}/stdlib/csv/from/).
Place the following at the beginning of your query to use the sample data:

View File

@ -15,9 +15,9 @@ canonical: /{{< latest "influxdb" "v2" >}}/query-data/flux/sort-limit/
v2: /influxdb/v2.0/query-data/flux/sort-limit/
---
Use the [`sort()`function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/sort)
Use the [`sort()`function](/{{< latest "flux" >}}/stdlib/universe/sort)
to order records within each table by specific columns and the
[`limit()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/limit)
[`limit()` function](/{{< latest "flux" >}}/stdlib/universe/limit)
to limit the number of records in output tables to a fixed number, `n`.
If you're just getting started with Flux queries, check out the following:
@ -39,7 +39,7 @@ from(bucket:"db/rp")
|> sort(columns:["region", "host", "_value"])
```
The [`limit()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/limit)
The [`limit()` function](/{{< latest "flux" >}}/stdlib/universe/limit)
limits the number of records in output tables to a fixed number, `n`.
The following example shows up to 10 records from the past hour.
@ -65,6 +65,6 @@ from(bucket:"db/rp")
```
You now have created a Flux query that sorts and limits data.
Flux also provides the [`top()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/top)
and [`bottom()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/selectors/bottom)
Flux also provides the [`top()`](/{{< latest "flux" >}}/stdlib/universe/top)
and [`bottom()`](/{{< latest "flux" >}}/stdlib/universe/bottom)
functions to perform both of these functions at the same time.

View File

@ -25,7 +25,7 @@ list_code_example: |
---
The Flux `sql` package provides functions for working with SQL data sources.
[`sql.from()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/sql/from/) lets you query SQL data sources
[`sql.from()`](/{{< latest "flux" >}}/stdlib/sql/from/) lets you query SQL data sources
like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/),
and [SQLite](https://www.sqlite.org/index.html), and use the results with InfluxDB
dashboards, tasks, and other operations.
@ -88,7 +88,7 @@ sql.from(
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}
_See the [`sql.from()` documentation](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/sql/from/) for
_See the [`sql.from()` documentation](/{{< latest "flux" >}}/stdlib/sql/from/) for
information about required function parameters._
## Join SQL data with data in InfluxDB

View File

@ -94,7 +94,7 @@ Table: keys: [_start, _stop, _field, _measurement]
{{% /truncate %}}
## Windowing data
Use the [`window()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/window)
Use the [`window()` function](/{{< latest "flux" >}}/stdlib/universe/window)
to group your data based on time bounds.
The most common parameter passed with the `window()` is `every` which
defines the duration of time between windows.
@ -107,7 +107,7 @@ dataSet
```
{{% note %}}
The `every` parameter supports all [valid duration units](/{{< latest "influxdb" "v2" >}}/reference/flux/language/types/#duration-types),
The `every` parameter supports all [valid duration units](/{{< latest "flux" >}}/language/types/#duration-types),
including **calendar months (`1mo`)** and **years (`1y`)**.
{{% /note %}}
@ -183,14 +183,14 @@ When visualized in the InfluxDB UI, each window table is displayed in a differen
![Windowed data](/img/flux/simple-windowed-data.png)
## Aggregate data
[Aggregate functions](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates) take the values
[Aggregate functions](/{{< latest "flux" >}}/stdlib/universe) take the values
of all rows in a table and use them to perform an aggregate operation.
The result is output as a new value in a single-row table.
Since windowed data is split into separate tables, aggregate operations run against
each table separately and output new tables containing only the aggregated value.
For this example, use the [`mean()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/mean)
For this example, use the [`mean()` function](/{{< latest "flux" >}}/stdlib/universe/mean)
to output the average of each window:
```js
@ -254,7 +254,7 @@ These represent the lower and upper bounds of the time window.
Many Flux functions rely on the `_time` column.
To further process your data after an aggregate function, you need to re-add `_time`.
Use the [`duplicate()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/duplicate) to
Use the [`duplicate()` function](/{{< latest "flux" >}}/stdlib/universe/duplicate) to
duplicate either the `_start` or `_stop` column as a new `_time` column.
```js
@ -342,7 +342,7 @@ With the aggregate values in a single table, data points in the visualization ar
You have now created a Flux query that windows and aggregates data.
The data transformation process outlined in this guide should be used for all aggregation operations.
Flux also provides the [`aggregateWindow()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow)
Flux also provides the [`aggregateWindow()` function](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow)
which performs all these separate functions for you.
The following Flux query will return the same results:

View File

@ -42,8 +42,8 @@ When performing any math operation in a Flux query, you must complete the follow
1. Specify the [bucket](/{{< latest "influxdb" "v2" >}}/query-data/get-started/#buckets) to query from and the time range to query.
2. Filter your data by measurements, fields, and other applicable criteria.
3. Align values in one row (required to perform math in Flux) by using one of the following functions:
- To query **from multiple** data sources, use the [`join()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/join/).
- To query **from the same** data source, use the [`pivot()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/pivot/).
- To query **from multiple** data sources, use the [`join()` function](/{{< latest "flux" >}}/stdlib/universe/join/).
- To query **from the same** data source, use the [`pivot()` function](/{{< latest "flux" >}}/stdlib/universe/pivot/).
For examples using the `join()` function to calculate percentages and more examples of calculating percentages, see [Calculate percentages with Flux](/{{< latest "influxdb" "v2" >}}/query-data/flux/calculate-percentages/).
@ -73,7 +73,7 @@ data
## Calculate a percentage from two fields
Use the `data` variable created above, and then use the [`map()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/map/) to divide one field by another, multiply by 100, and add a new `percent` field to store the percentage values in.
Use the `data` variable created above, and then use the [`map()` function](/{{< latest "flux" >}}/stdlib/universe/map/) to divide one field by another, multiply by 100, and add a new `percent` field to store the percentage values in.
```js
data
@ -89,7 +89,7 @@ data
## Calculate a percentage using aggregate functions
Use [`aggregateWindow()`](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/aggregates/aggregatewindow) to window data by time and perform an aggregate function on each window.
Use [`aggregateWindow()`](/{{< latest "flux" >}}/stdlib/universe/aggregatewindow) to window data by time and perform an aggregate function on each window.
```js
from(bucket:"<database>/<retention_policy>")

View File

@ -4375,7 +4375,7 @@ InfluxDB then rounds those averages down to the nearest integer.
_InfluxQL does not currently support histogram generation.
For information about creating histograms with data stored in InfluxDB, see
[Flux's `histogram()` function](/{{< latest "influxdb" "v2" >}}/reference/flux/stdlib/built-in/transformations/histogram)._
[Flux's `histogram()` function](/{{< latest "flux" >}}/stdlib/universe/histogram)._
### LN()

View File

@ -2,7 +2,7 @@
title: Example post
description: This is just an example post to show the format of new 2.0 posts
weight: 1
draft: true
# draft: true
related:
- /influxdb/v2.0/write-data/
- /influxdb/v2.0/write-data/quick-start
@ -12,6 +12,10 @@ products: [cloud, oss, enterprise]
This is a paragraph. Lorem ipsum dolor ({{< icon "trash" >}}) sit amet, consectetur adipiscing elit. Nunc rutrum, metus id scelerisque euismod, erat ante suscipit nibh, ac congue enim risus id est. Etiam tristique nisi et tristique auctor. Morbi eu bibendum erat. Sed ullamcorper, dui id lobortis efficitur, mauris odio pharetra neque, vel tempor odio dolor blandit justo.
[Ref link][foo]
[foo]: https://docs.influxadata.com
This is **bold** text. This is _italic_ text. This is _**bold and italic**_.
{{< nav-icon "account" >}}

View File

@ -0,0 +1,28 @@
---
title: Flux documentation
description: >
Flux is a open source functional data scripting language designed for querying,
analyzing, and acting on data.
menu:
flux_0_x:
name: Flux 0.x
weight: 1
aliases:
- /influxdb/v2.0/reference/flux/
- /influxdb/cloud/reference/flux/
---
Flux is an open source functional data scripting language designed for querying,
analyzing, and acting on data.
Flux supports multiple data source types, including:
- Time series databases (such as [InfluxDB](/flux/v0.x/query-data/influxdb/))
- [Relational SQL databases](/flux/v0.x/query-data/sql/)
(such as [MySQL](/flux/v0.x/query-data/sql/mysql/) and [PostgreSQL](/flux/v0.x/query-data/sql/postgresql/))
- [CSV](/flux/v0.x/query-data/csv/)
<!-- - **Prometheus-formatted metrics** from HTTP-accessible endpoints -->
Flux unifies code for querying, processing, writing, and acting on data into a single syntax.
The language is designed to be usable, readable, flexible, composable, testable, contributable, and shareable.
<a href="/flux/v0.x/get-started/" class="btn">Get started with Flux</a>

View File

@ -0,0 +1,18 @@
---
title: Work with Flux data types
description: >
Learn how to work with different Flux data types.
menu:
flux_0_x:
name: Work with Flux types
weight: 4
---
A Flux **data type** defines the set of possible values and operations.
Flux is **statically typed**, meaning data types are never explicitly declared
as part of the Flux syntax (except as part of a [builtin statement](/flux/v0.x/spec/system-built-ins/))
and types are inferred from how a variable is used.
Flux data types are organized into the following:
{{< children hlevel="h2" >}}

View File

@ -0,0 +1,19 @@
---
title: Work with basic data types
seotitle: Work with basic Flux data types
list_title: Basic types
description: >
All Flux data types are constructed from **basic types**: boolean, bytes,
duration, string, time, float, integer, uintegers, and null.
menu:
flux_0_x:
name: Basic types
parent: Work with Flux types
weight: 101
---
All Flux data types are constructed from the following **basic types**:
{{< children type="anchored-list" >}}
{{< children readmore=true >}}

View File

@ -0,0 +1,140 @@
---
title: Work with booleans
list_title: Boolean
description: >
A **boolean** type represents a truth value (`true` or `false`).
Learn how to work with boolean data types in Flux.
menu:
flux_0_x:
name: Boolean
parent: Basic types
weight: 201
flux/v0.x/tags: ["basic types", "data types"]
related:
- /flux/v0.x/stdlib/universe/bool/
- /flux/v0.x/stdlib/universe/tobool/
list_code_example: |
```js
true
false
```
---
A **boolean** type represents a truth value (`true` or `false`).
**Type name**: `bool`
- [Boolean syntax](#boolean-syntax)
- [Convert data types to booleans](#convert-data-types-to-booleans)
- [Negate boolean values](#negate-boolean-values)
## Boolean syntax
Boolean literals are represented by the following:
```js
true
false
```
## Convert data types to booleans
Use the [`bool()` function](/flux/v0.x/stdlib/universe/bool/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to booleans:
- **string**: value must be `"true"` or `"false"`.
- **float**: value must be `0.0` (false) or `1.0` (true).
- **int**: value must be `0` (false) or `1` (true).
- **uint**: value must be `0` (false) or `1` (true).
```js
bool(v: "true")
// Returns true
bool(v: 0.0)
// Returns false
bool(v: 0)
// Returns false
bool(v: uint(v: 1))
// Returns true
```
### Convert columns to booleans
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to booleans.
**To convert the `_value` column to booleans**, use the [`toBool()` function](/flux/v0.x/stdlib/universe/bool/).
{{% note %}}
`toBool()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toBool()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(float)</span>_ |
| :------------------- | ------------------------------------------------: |
| 2021-01-01T00:00:00Z | 1.0 |
| 2021-01-01T02:00:00Z | 0.0 |
| 2021-01-01T03:00:00Z | 0.0 |
| 2021-01-01T04:00:00Z | 1.0 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(bool)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | true |
| 2021-01-01T02:00:00Z | false |
| 2021-01-01T03:00:00Z | false |
| 2021-01-01T04:00:00Z | true |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to booleans**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`bool()`](/flux/v0.x/stdlib/universe/bool/) to convert columns values to booleans.
```js
data
|> map(fn: (r) => ({ r with running: bool(v: r.running) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | running _<span style="opacity:.5">(int)</span>_ |
| :------------------- | ----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 0 |
| 2021-01-01T03:00:00Z | 0 |
| 2021-01-01T04:00:00Z | 1 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | running _<span style="opacity:.5">(bool)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | true |
| 2021-01-01T02:00:00Z | false |
| 2021-01-01T03:00:00Z | false |
| 2021-01-01T04:00:00Z | true |
{{% /flex-content %}}
{{< /flex >}}
## Negate boolean values
To negate boolean values, use the [`not` logical operator](/flux/v0.x/spec/operators/#logical-operators).
```js
not true
// Returns false
not false
// Returns true
```

View File

@ -0,0 +1,68 @@
---
title: Work with bytes types
list_title: Bytes
description: >
A **bytes** type represents a sequence of byte values.
Learn how to work with bytes data types in Flux.
menu:
flux_0_x:
name: Bytes
parent: Basic types
weight: 201
flux/v0.x/tags: ["basic types", "data types"]
related:
- /flux/v0.x/stdlib/universe/bytes/
---
A **bytes** type represents a sequence of byte values.
**Type name**: `bytes`
- [Bytes syntax](#bytes-syntax)
- [Convert a column to bytes](#convert-a-column-to-bytes)
## Bytes syntax
Flux does not provide a bytes literal syntax.
Use the [`bytes()` function](/flux/v0.x/stdlib/universe/bytes) to convert a
**string** into bytes.
```js
bytes(v: "hello")
// Returns [104 101 108 108 111]
```
{{% note %}}
Only string types can be converted to bytes.
{{% /note %}}
## Convert a column to bytes
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`bytes()`](/flux/v0.x/stdlib/universe/bytes/) to convert column values to bytes.
```js
data
|> map(fn: (r) => ({ r with _value: time(v: r._value) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(string)</span>_ |
| :------------------- | -------------------------------------------------: |
| 2021-01-01T00:00:00Z | foo |
| 2021-01-01T02:00:00Z | bar |
| 2021-01-01T03:00:00Z | baz |
| 2021-01-01T04:00:00Z | quz |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(bytes)</span>_ |
| :------------------- | -------------------------------------------------: |
| 2021-01-01T00:00:00Z | [102 111 111] |
| 2021-01-01T02:00:00Z | [98 97 114] |
| 2021-01-01T03:00:00Z | [98 97 122] |
| 2021-01-01T04:00:00Z | [113 117 122] |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -0,0 +1,137 @@
---
title: Work with durations
list_title: Duration
description: >
A **duration** type represents a length of time with nanosecond precision
Learn how to work with duration data types in Flux.
menu:
flux_0_x:
name: Duration
parent: Basic types
weight: 201
flux/v0.x/tags: ["basic types", "data types"]
related:
- /flux/v0.x/stdlib/universe/duration/
list_code_example: |
```js
1ns
1h
1w
3d12h4m25s
```
---
A **duration** type represents a length of time with nanosecond precision.
**Type name**: `duration`
- [Duration syntax](#duration-syntax)
- [Convert data types to durations](#convert-data-types-to-durations)
- [Operate on durations](#operate-on-durations)
## Duration syntax
Duration literals contain integers and unit specifiers.
Flux supports the following unit specifiers:
- `ns`: nanosecond
- `us`: microsecond
- `ms`: millisecond
- `s`: second
- `m`: minute
- `h`: hour
- `d`: day
- `w`: week
- `mo`: calendar month
- `y`: calendar year
```js
1ns // 1 nanosecond
1us // 1 microsecond
1ms // 1 millisecond
1s // 1 second
1m // 1 minute
1h // 1 hour
1d // 1 day
1w // 1 week
1mo // 1 calendar month
1y // 1 calendar year
3d12h4m25s // 3 days, 12 hours, 4 minutes, and 25 seconds
```
## Convert data types to durations
Use the [`duration()` function](/flux/v0.x/stdlib/universe/duration/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to durations:
- **string**: parsed as a duration string and converted to a duration.
- **int**: parsed as nanoseconds and converted to a duration.
- **uint**: parsed as nanoseconds and converted to a duration.
```js
duration(v: "1h30m")
// Returns 1h30m
duration(v: 1000000)
// Returns 1ms
duration(v: uint(v: 3000000000))
// Returns 3s
```
{{% note %}}
**Flux does not support duration columns.**
{{% /note %}}
## Operate on durations
- [Perform arithmetic operations on durations](#perform-arithmetic-operations-on-durations)
- [Add a duration to a time value](#add-a-duration-to-a-time-value)
- [Subtract a duration from a time value](#subtract-a-duration-from-a-time-value)
### Perform arithmetic operations on durations
To perform operations like adding, subtracting, multiplying, or dividing duration values:
1. Use [`int()`](/flux/v0.x/stdlib/universe/int/) or [`uint()`](/flux/v0.x/stdlib/universe/uint/)
to convert duration values to numeric values.
2. Use [arithmetic operators](/flux/v0.x/spec/operators/#arithmetic-operators) to
operate on numeric values.
3. Use [`duration()`](/flux/v0.x/stdlib/universe/duration/) to convert the calculated
numeric value into a duration.
```js
duration(v: int(v: 6h4m) + int(v: 22h32s))
// Returns 1d4h4m32s
duration(v: int(v: 22h32s) - int(v: 6h4m))
// Returns 15h56m32s
duration(v: int(v: 32m10s) * 10)
// Returns 5h21m40s
duration(v: int(v: 24h) / 2)
// Returns 12h
```
### Add a duration to a time value
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.addDuration()`](/flux/v0.x/stdlib/experimental/addduration/)
to add a duration to a time value.
```js
import "experimental"
experimental.addDuration(d: 1w, to: 2021-01-01T00:00:00Z)
// Returns 2021-01-08T00:00:00.000000000Z
```
### Subtract a duration from a time value
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.subDuration()`](/flux/v0.x/stdlib/experimental/subduration/)
to subtract a duration from a time value.
```js
import "experimental"
experimental.subDuration(d: 1w, from: 2021-01-01T00:00:00Z)
// Returns 2020-12-25T00:00:00.000000000Z
```

View File

@ -0,0 +1,238 @@
---
title: Work with floats
list_title: Float
description: >
A **float** type represents a [IEEE-754](https://standards.ieee.org/standard/754-2019.html)
64-bit floating-point number.
Learn how to work with float types in Flux.
menu:
flux_0_x:
name: Float
parent: Basic types
weight: 202
flux/v0.x/tags: ["basic types", "numeric types", "data types"]
related:
- /flux/v0.x/stdlib/universe/float/
- /flux/v0.x/stdlib/universe/tofloat/
list_code_example: |
```js
0.0
123.4
-123.456
```
---
A **float** type represents a [IEEE-754](https://standards.ieee.org/standard/754-2019.html)
64-bit floating-point number.
**Type name:** `float`
- [Float syntax](#float-syntax)
- [Convert data types to floats](#convert-data-types-to-floats)
- [Operate on floats](#operate-on-floats)
## Float syntax
A float literal contains a decimal integer, a decimal point, and a decimal fraction.
```js
0.0
123.4
-123.456
```
- [Scientific notation](#scientific-notation)
- [Infinity](#infinity)
- [Not a Number (NaN)](#not-a-number)
### Scientific notation
Flux does not support scientific notation float literal syntax.
However, you can use [`float()`](/flux/v0.x/stdlib/universe/float/) to convert
a **scientific notation string** into a float type.
```js
1.23456e+78
// Error: error @1:8-1:9: undefined identifier e
float(v: "1.23456e+78")
// Returns 1.23456e+78 (float)
```
### Infinity
Flux does not support infinite float literal syntax (`+Inf` and `-Inf`).
However, you can use [`float()`](/flux/v0.x/stdlib/universe/float/) to convert
a **infinite string** into a float type.
```js
+Inf
// Error: error @1:2-1:5: undefined identifier Inf
float(v: "+Inf")
// Returns +Inf (float)
```
### Not a Number
Flux does not support Not a Number (NaN) float literal syntax.
However, you can use [`float()`](/flux/v0.x/stdlib/universe/float/) to convert
a **NaN string** into a float type.
```js
NaN
// Error: error @1:2-1:5: undefined identifier NaN
float(v: "NaN")
// Returns NaN (float)
```
## Convert data types to floats
Use the [`float()` function](/flux/v0.x/stdlib/universe/float/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to floats:
- **string**: must be a numeric string or [scientific notation](#scientific-notation)
- **bool**: `true` converts to `1.0`, `false` converts to `0.0`
- **int**
- **uint**
```js
float(v: "1.23")
// 1.23
float(v: true)
// Returns 1.0
float(v: 123)
// Returns 123.0
```
### Convert columns to floats
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to floats.
**To convert the `_value` column to floats**, use the [`toFloat()` function](/flux/v0.x/stdlib/universe/tofloat/).
{{% note %}}
`toFloat()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toFloat()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(int)</span>_ |
| :------------------- | ----------------------------------------------: |
| 2021-01-01T00:00:00Z | 10 |
| 2021-01-01T02:00:00Z | 20 |
| 2021-01-01T03:00:00Z | 30 |
| 2021-01-01T04:00:00Z | 40 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(float)</span>_ |
| :------------------- | ------------------------------------------------: |
| 2021-01-01T00:00:00Z | 10.0 |
| 2021-01-01T02:00:00Z | 20.0 |
| 2021-01-01T03:00:00Z | 30.0 |
| 2021-01-01T04:00:00Z | 40.0 |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to floats**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`float()`](/flux/v0.x/stdlib/universe/float/) to convert columns values to floats.
```js
data
|> map(fn: (r) => ({ r with index: float(v: r.index) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | index _<span style="opacity:.5">(int)</span>_ |
| :------------------- | --------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | index _<span style="opacity:.5">(float)</span>_ |
| :------------------- | ----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1.0 |
| 2021-01-01T02:00:00Z | 2.0 |
| 2021-01-01T03:00:00Z | 3.0 |
| 2021-01-01T04:00:00Z | 4.0 |
{{% /flex-content %}}
{{< /flex >}}
## Operate on floats
- [Perform arithmetic operations on floats](#perform-arithmetic-operations-on-floats)
- [Compare float values](#compare-float-values)
- [Round float values](#round-float-values)
- [Flux math package](#flux-math-package)
### Perform arithmetic operations on floats
To perform operations like adding, subtracting, multiplying, or dividing float values,
use [Flux arithmetic operators](/flux/v0.x/spec/operators/#arithmetic-operators).
Operands must be the same type.
```js
1.23 + 45.67
// Returns 46.9
1.23 - 45.67
// Returns -44.440000000000005
float(v: "12345e+67") * 100.0
// Returns 1.2345000000000001e+73
144.0 / 12.0
// Returns 12.0
10.0 ^ 2.0
// Returns 100.0
```
{{% note %}}
#### Inherent rounding errors in floating-point arithmetic
To fit an infinite number of real values into a finite number of bits,
computer systems must round floating-point values in arithmetic operations.
This results in small rounding errors in some operations.
{{% /note %}}
### Compare float values
Use [Flux comparison operators](/flux/v0.x/spec/operators/#comparison-operators)
to compare float values.
Operands must be the same type.
The operation returns a float.
```js
12345600.0 == float(v: "1.23456e+07")
// Returns true
1.2 > -2.1
// Returns true
```
### Round float values
1. Import the [`math` package](/flux/v0.x/stdlib/math/).
2. Use [`math.round()`](/flux/v0.x/stdlib/math/round/) to round to the nearest whole number.
```js
import "math"
math.round(x: 1.54)
// Returns 2.0
```
### Flux math package
Use the [`math` package](/flux/v0.x/stdlib/math/) to perform
operations on float values.

View File

@ -0,0 +1,204 @@
---
title: Work with integers
list_title: Integer
description: >
An **integer** type represents a signed 64-bit integer.
Learn how to work with integer types in Flux.
menu:
flux_0_x:
name: Integer
parent: Basic types
weight: 202
flux/v0.x/tags: ["basic types", "numeric types", "data types"]
related:
- /flux/v0.x/stdlib/universe/int/
- /flux/v0.x/stdlib/universe/toint/
list_code_example: |
```js
0
2
1254
-1254
```
---
An **integer** type represents a signed 64-bit integer.
**Type name**: `int`
**Min value**: `-9223372036854775808`
**Max value**: `9223372036854775807`
- [Integer syntax](#integer-syntax)
- [Convert data types to integers](#convert-data-types-to-integers)
- [Operate on integers](#operate-on-integers)
## Integer syntax
An integer literal contains one or more digits (0-9) optionally preceded by
`-` to indicate a negative number.
`-0` is equivalent to `0` and is not a negative number.
```js
0
2
1254
-1254
```
## Convert data types to integers
Use the [`int()` function](/flux/v0.x/stdlib/universe/int/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to integers:
- **string**: returns the integer equivalent of the numeric string (`[0-9]`)
- **bool**: returns `1` for `true` or `0` for `false`
- **duration**: returns the number of nanoseconds in the duration
- **time**: returns the equivalent [nanosecond epoch timestamp](/influxdb/cloud/reference/glossary/#unix-timestamp)
- **float**: truncates the float value at the decimal
- **uint**: returns the integer equivalent of the unsigned integer
```js
int(v: "123")
// 123
int(v: true)
// Returns 1
int(v: 1d3h24m)
// Returns 98640000000000
int(v: 2021-01-01T00:00:00Z)
// Returns 1609459200000000000
int(v: 12.54)
// Returns 12
```
{{% note %}}
#### Round float values before converting to integers
Being Flux _truncates_ the [float](/flux/v0.x/data-types/basic/float/) value at the decimal when converting to an integer, for example `12.54` to `12`, you may want to round float values to the nearest whole number `12.54` to `13` before converting. To do this:
1. Import the [`math` package](/flux/v0.x/stdlib/math/).
2. Use [`math.round()`](/flux/v0.x/stdlib/math/round/) to round the the float value
before converting it to an integer.
```js
import "math"
int(v: math.round(x: 12.54))
// Returns 13
```
{{% /note %}}
### Convert columns to integers
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to integers.
**To convert the `_value` column to integers**, use the [`toInt()` function](/flux/v0.x/stdlib/universe/toint/).
{{% note %}}
`toInt()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toInt()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(float)</span>_ |
| :------------------- | ------------------------------------------------: |
| 2021-01-01T00:00:00Z | 1.23 |
| 2021-01-01T02:00:00Z | 4.56 |
| 2021-01-01T03:00:00Z | 7.89 |
| 2021-01-01T04:00:00Z | 10.11 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(int)</span>_ |
| :------------------- | ----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 4 |
| 2021-01-01T03:00:00Z | 7 |
| 2021-01-01T04:00:00Z | 10 |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to integers**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`int()`](/flux/v0.x/stdlib/universe/int/) to convert columns values to integers.
```js
data
|> map(fn: (r) => ({ r with uid: int(v: r.uid) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | index _<span style="opacity:.5">(string)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | 100010024 |
| 2021-01-01T02:00:00Z | 100050213 |
| 2021-01-01T03:00:00Z | 200130763 |
| 2021-01-01T04:00:00Z | 101420099 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | index _<span style="opacity:.5">(int)</span>_ |
| :------------------- | --------------------------------------------: |
| 2021-01-01T00:00:00Z | 100010024 |
| 2021-01-01T02:00:00Z | 100050213 |
| 2021-01-01T03:00:00Z | 200130763 |
| 2021-01-01T04:00:00Z | 101420099 |
{{% /flex-content %}}
{{< /flex >}}
## Operate on integers
- [Perform arithmetic operations on integers](#perform-arithmetic-operations-on-integers)
- [Compare integers](#compare-integers)
### Perform arithmetic operations on integers
To perform operations like adding, subtracting, multiplying, or dividing integers,
use [Flux arithmetic operators](/flux/v0.x/spec/operators/#arithmetic-operators).
Operands must be the same type.
The operation returns an integer.
{{% note %}}
When operating with integer operands, fractional results are truncated at the decimal.
{{% /note %}}
```js
1 + 45
// Returns 46
1 - 45
// Returns -44
12 * 100
// Returns 1200
100 / 200
// Returns 0
10 ^ 2
// Returns 100
```
### Compare integers
Use [Flux comparison operators](/flux/v0.x/spec/operators/#comparison-operators)
to compare integers.
Operands must be the same type.
The operation returns a boolean.
```js
12345600 == 12345601
// Returns false
2 > -2
// Returns true
```

View File

@ -0,0 +1,61 @@
---
title: Work with null types
list_title: "Null"
description: >
The **null type** represents a missing or unknown value.
Learn how to work with null types in Flux.
menu:
flux_0_x:
name: "Null"
parent: Basic types
weight: 204
flux/v0.x/tags: ["basic types", "data types"]
---
The **null type** represents a missing or unknown value.
**Type name**: `null`
- [Null syntax](#null-syntax)
- [Check if a column value is null](#check-if-a-column-value-is-null)
## Null syntax
Null types exist in [columns](/flux/v0.x/get-started/data-model/#column) of
other [basic types](/flux/v0.x/data-types/basic/), but there is no literal syntax
to represent a _null_ value.
{{% note %}}
An empty string (`""`) **is not** a _null_ value.
{{% /note %}}
## Check if a column value is null
In functions that iterate over rows (such as [`filter()`](/flux/v0.x/stdlib/universe/filter/)
or [`map()`](/flux/v0.x/stdlib/universe/map/)), use the
[`exists` logical operator](/flux/v0.x/spec/operators/#logical-operators) to check
if a column value is _null_.
##### Filter out rows with null values
```js
data
|> filter(fn: (r) => exists r._value)
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value |
| :------------------- | ------: |
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T02:00:00Z | |
| 2021-01-01T03:00:00Z | 2.5 |
| 2021-01-01T04:00:00Z | |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value |
| :------------------- | ------: |
| 2021-01-01T00:00:00Z | 1.2 |
| 2021-01-01T03:00:00Z | 2.5 |
{{% /flex-content %}}
{{< /flex >}}

View File

@ -0,0 +1,217 @@
---
title: Work with strings
list_title: String
description: >
A **string** type represents a sequence of characters.
Learn how to work with string data types in Flux.
menu:
flux_0_x:
name: String
parent: Basic types
weight: 201
flux/v0.x/tags: ["basic types", "data types"]
aliases:
- /influxdb/v2.0/reference/flux/language/string-interpolation/
- /influxdb/cloud/reference/flux/language/string-interpolation/
related:
- /flux/v0.x/stdlib/universe/string/
- /flux/v0.x/stdlib/universe/tostring/
- /flux/v0.x/stdlib/strings/
list_code_example: |
```js
"abc"
"string with double \" quote"
"string with backslash \\"
"日本語"
"\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
```
---
A **string** type represents a sequence of characters.
Strings are immutable and cannot be modified once created.
**Type name**: `string`
- [String syntax](#string-syntax)
- [Convert data types to strings](#convert-data-types-to-strings)
- [Operate on strings](#operate-on-strings)
- [Interpolate strings](#interpolate-strings)
- [Concatenate strings](#concatenate-strings)
## String syntax
A **string** literal is represented by a sequence of characters enclosed in double quotes (`"`).
Any character may appear inside a string literal except an unescaped double quote.
String literals support several [escape sequences](/flux/v0.x/spec/lexical-elements/#string-literals)
and [hex encoding using `\x` as a prefix](/flux/v0.x/spec/lexical-elements/#string-literals).
```js
"abc"
"string with double \" quote"
"string with backslash \\"
"日本語"
"\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e"
```
## Convert data types to strings
Use the [`string()` function](/flux/v0.x/stdlib/universe/string/) to convert
other [basic types](/flux/v0.x/data-types/basic/) to strings:
- boolean
- bytes
- duration
- float
- int
- uint
- time
```js
string(v: 42)
// Returns "42"
```
To convert a [regular expression](/flux/v0.x/data-types/regexp/) to a string:
1. Import the [`regexp` package](/flux/v0.x/stdlib/regexp/).
2. Use [`regexp.getString()`](/flux/v0.x/stdlib/regexp/getstring/) and provide
the regular expression to convert to a string.
```js
import "regexp"
regexp.getString(r: /[a-zA-Z]/)
// Returns [a-zA-Z] (string)
```
### Convert columns to strings
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to strings.
**To convert the `_value` column to strings**,
use the [`toString()` function](/flux/v0.x/stdlib/universe/tostring/).
{{% note %}}
`toString()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toString()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(int)</span>_ |
| :------------------- | ----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(string)</span>_ |
| :------------------- | -------------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to strings**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`string()`](/flux/v0.x/stdlib/universe/string/) to convert columns values to strings.
```js
data
|> map(fn: (r) => ({ r with level: string(v: r.level) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | level _<span style="opacity:.5">(int)</span>_ |
| :------------------- | --------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | level _<span style="opacity:.5">(string)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 2 |
| 2021-01-01T03:00:00Z | 3 |
| 2021-01-01T04:00:00Z | 4 |
{{% /flex-content %}}
{{< /flex >}}
## Operate on strings
Use functions in the [Flux strings package](/flux/v0.x/stdlib/strings/) to perform
operations including:
- [Compare two strings](/flux/v0.x/stdlib/strings/compare/)
- [Replace substrings in a string](/flux/v0.x/stdlib/strings/replace/)
- [Return the length of a string](/flux/v0.x/stdlib/strings/strlen/)
- [Split a string into an array](/flux/v0.x/stdlib/strings/split/)
- [Join an array into a string](/flux/v0.x/stdlib/strings/joinstr/)
- [and more](/flux/v0.x/stdlib/strings/)
## Interpolate strings
To interpolate strings in another Flux string, enclose embedded [expressions](/flux/v0.x/spec/expressions/)
in a dollar sign and curly braces `${}`.
Flux replaces the placeholder with the result of the embedded expression and
returns a string literal.
```js
name = "John"
"My name is ${name}."
// My name is John.
d = 1m
"the answer is ${d}"
// the answer is 1m
t0 = 2016-06-13T17:43:50Z
"the answer is ${t0}"
// the answer is 2016-06-13T17:43:50.000000000Z
p = {name: "John", age: 42}
"My name is ${p.name} and I'm ${p.age} years old."
// My name is John and I'm 42 years old.
```
_String interpolation expressions must satisfy the
[Stringable constraint](/flux/v0.x/spec/types/#stringable-constraint)._
## Concatenate strings
To concatenate Flux strings, use the `+` operator between string values or
[expressions](/flux/v0.x/spec/expressions/) that resolve to strings.
Flux resolves expressions and returns a single concatenated string.
{{% note %}}
Concatenated expressions must resolve to strings.
{{% /note %}}
```js
name = "John"
"My name is " + name + "."
// My name is John.
d = 1m
"the answer is " + string(v: d)
// the answer is 1m
t0 = 2016-06-13T17:43:50Z
"the answer is " + string(v: t0)
// the answer is 2016-06-13T17:43:50.000000000Z
p = {name: "John", age: 42}
"My name is " + p.name + " and I'm " + string(v: p.age) + " years old."
// My name is John and I'm 42 years old.
```

View File

@ -0,0 +1,246 @@
---
title: Work with time types
list_title: Time
description: >
A **time** type represents a single point in time with nanosecond precision.
Learn how to work with time data types in Flux.
menu:
flux_0_x:
name: Time
parent: Basic types
weight: 201
flux/v0.x/tags: [basic types, data types, date/time]
related:
- /flux/v0.x/stdlib/universe/time/
- /flux/v0.x/stdlib/universe/totime/
list_code_example: |
```js
2021-01-01
2021-01-01T00:00:00Z
2021-01-01T00:00:00.000Z
```
---
A **time** type represents a single point in time with nanosecond precision.
**Type name**: `time`
- [Time syntax](#time-syntax)
- [Convert data types to time](#convert-data-types-to-time)
- [Operate on time](#operate-on-time)
## Time syntax
Time literals are represented by [RFC3339 timestamps](/influxdb/cloud/reference/glossary/#rfc3339-timestamp).
```
YYYY-MM-DD
YYYY-MM-DDT00:00:00Z
YYYY-MM-DDT00:00:00.000Z
```
## Convert data types to time
Use the [`time()` function](/flux/v0.x/stdlib/universe/time/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to time:
- **string**: parsed as an [RFC3339 timestamp](/influxdb/cloud/reference/glossary/#rfc3339-timestamp)
and converted to a time value.
- **int**: parsed as a [Unix nanosecond timestamp](/influxdb/cloud/reference/glossary/#unix-timestamp)
and converted to a time value.
- **uint**: parsed as a [Unix nanosecond timestamp](/influxdb/cloud/reference/glossary/#unix-timestamp)
and converted to a time value.
```js
time(v: "2021-01-01")
// Returns 2021-01-01T00:00:00.000000000Z
time(v: 1609459200000000000)
// Returns 2021-01-01T00:00:00.000000000Z
time(v: uint(v: 1609459200000000000))
// Returns 2021-01-01T00:00:00.000000000Z
```
### Convert columns to time
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to time.
**To convert the `_value` column to time**, use the [`toTime()` function](/flux/v0.x/stdlib/universe/totime/).
{{% note %}}
`toTime()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toTime()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(int)</span>_ |
| :------------------------------------------------ | ----------------------------------------------: |
| {{% nowrap %}}2021-01-01T00:00:00Z{{% /nowrap %}} | 10000000000 |
| {{% nowrap %}}2021-01-01T02:00:00Z{{% /nowrap %}} | 20000000000 |
| {{% nowrap %}}2021-01-01T03:00:00Z{{% /nowrap %}} | 30000000000 |
| {{% nowrap %}}2021-01-01T04:00:00Z{{% /nowrap %}} | 40000000000 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(time)</span>_ |
| :------------------------------------------------ | ------------------------------------------------: |
| {{% nowrap %}}2021-01-01T00:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:10Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T02:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:20Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T03:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:30Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T04:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:40Z{{% /nowrap %}} |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to time**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`time()`](/flux/v0.x/stdlib/universe/time/) to convert columns values to time.
```js
data
|> map(fn: (r) => ({ r with epoch_ns: time(v: r.epoch_ns) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | epoch_ns _<span style="opacity:.5">(int)</span>_ |
| :------------------------------------------------ | -----------------------------------------------: |
| {{% nowrap %}}2021-01-01T00:00:00Z{{% /nowrap %}} | 10000000000 |
| {{% nowrap %}}2021-01-01T02:00:00Z{{% /nowrap %}} | 20000000000 |
| {{% nowrap %}}2021-01-01T03:00:00Z{{% /nowrap %}} | 30000000000 |
| {{% nowrap %}}2021-01-01T04:00:00Z{{% /nowrap %}} | 40000000000 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | epoch_ns _<span style="opacity:.5">(time)</span>_ |
| :------------------------------------------------ | ------------------------------------------------: |
| {{% nowrap %}}2021-01-01T00:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:10Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T02:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:20Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T03:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:30Z{{% /nowrap %}} |
| {{% nowrap %}}2021-01-01T04:00:00Z{{% /nowrap %}} | {{% nowrap %}}1970-01-01T00:00:40Z{{% /nowrap %}} |
{{% /flex-content %}}
{{< /flex >}}
## Operate on time
- [Truncate timestamps to a specified unit](#truncate-timestamps-to-a-specified-unit)
- [Parse units of time from a timestamp](#parse-units-of-time-from-a-timestamp)
- [Add a duration to a time value](#add-a-duration-to-a-time-value)
- [Subtract a duration from a time value](#subtract-a-duration-from-a-time-value)
### Truncate timestamps to a specified unit
Truncating timestamps can be helpful when normalizing irregular timestamps.
To truncate timestamps to a specified unit:
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use [`date.truncate()`](/flux/v0.x/stdlib/date/truncate/), and provide the
unit of time to truncate to.
{{% note %}}
#### Truncate to weeks
When truncating a time value to the week (`1w`), weeks are determined using the
**Unix epoch (1970-01-01T00:00:00Z UTC)**. The Unix epoch was on a Thursday, so
all calculated weeks begin on Thursday.
{{% /note %}}
```js
t0 = 2021-01-08T14:54:10.023849Z
date.truncate(t: t0, unit: 1ms)
// Returns 2021-01-08T14:54:10.023000000Z
date.truncate(t: t0, unit: 1m)
// Returns 2021-01-08T14:54:00.000000000Z
date.truncate(t: t0, unit: 1w)
// Returns 2021-01-07T00:00:00.000000000Z
date.truncate(t: t0, unit: 1mo)
// Returns 2021-01-01T00:00:00.000000000Z
```
**To truncate the `_time` column, use [`truncateTimeColumn()`](/flux/v0.x/stdlib/universe/truncatetimecolumn/)**:
```js
data
|> truncateTimeColumn(unit: 1m)
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | _value |
| :------------------------------------------------ | -----: |
| {{% nowrap %}}2021-01-01T00:00:33Z{{% /nowrap %}} | 1.0 |
| {{% nowrap %}}2021-01-01T00:01:10Z{{% /nowrap %}} | 1.1 |
| {{% nowrap %}}2021-01-01T00:02:45Z{{% /nowrap %}} | 3.6 |
| {{% nowrap %}}2021-01-01T00:03:23Z{{% /nowrap %}} | 2.5 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | _value |
| :------------------------------------------------ | -----: |
| {{% nowrap %}}2021-01-01T00:00:00Z{{% /nowrap %}} | 1.0 |
| {{% nowrap %}}2021-01-01T00:01:00Z{{% /nowrap %}} | 1.1 |
| {{% nowrap %}}2021-01-01T00:02:00Z{{% /nowrap %}} | 3.6 |
| {{% nowrap %}}2021-01-01T00:03:00Z{{% /nowrap %}} | 2.5 |
{{% /flex-content %}}
{{< /flex >}}
### Parse units of time from a timestamp
To parse a specific unit of time from a time value:
1. Import the [`date` package](/flux/v0.x/stdlib/date/).
2. Use functions in the `date` package to return specific units of time from a timestamp.
```js
import "date"
t0 = 2021-01-08T14:54:10.023849Z
date.minute(t: t0)
// Returns 54
date.year(t: t0)
// Returns 2021
date.quarter(t: t0)
// Returns 1
```
### Add a duration to a time value
To add a [duration](/flux/v0.x/data-types/basic/duration/) to a time value:
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.addDuration()`](/flux/v0.x/stdlib/experimental/addduration/)
to add a duration to a time value.
```js
import "experimental"
experimental.addDuration(d: 1w, to: 2021-01-01T00:00:00Z)
// Returns 2021-01-08T00:00:00.000000000Z
```
### Subtract a duration from a time value
To subtract a [duration](/flux/v0.x/data-types/basic/duration/) from a time value:
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.subDuration()`](/flux/v0.x/stdlib/experimental/subduration/)
to subtract a duration from a time value.
```js
import "experimental"
experimental.subDuration(d: 1w, from: 2021-01-01T00:00:00Z)
// Returns 2020-12-25T00:00:00.000000000Z
```

View File

@ -0,0 +1,202 @@
---
title: Work with unsigned integers
list_title: UIntegers
description: >
An **unsigned integer** (uinteger) type represents a unsigned 64-bit integer.
Learn how to work with unsigned integer types in Flux.
menu:
flux_0_x:
name: UIntegers
parent: Basic types
weight: 202
flux/v0.x/tags: ["basic types", "numeric types", "data types"]
related:
- /flux/v0.x/stdlib/universe/uint/
- /flux/v0.x/stdlib/universe/touint/
list_code_example: |
```js
uint(v: 123)
```
---
An **unsigned integer** (uinteger) type represents a unsigned 64-bit integer.
**Type name**: `uint`
**Min value**: `0`
**Max value**: `18446744073709551615`
- [UInteger syntax](#uinteger-syntax)
- [Convert data types to uintegers](#convert-data-types-to-uintegers)
- [Operate on uintegers](#operate-on-uintegers)
## UInteger syntax
Flux does not provide a uinteger literal syntax.
However, you can use [`uint()`](/flux/v0.x/stdlib/universe/uint/) to [convert
basic data types into a uinteger](#convert-data-types-to-uintegers).
```js
uint(v: 123)
// Returns 123 (uint)
```
## Convert data types to uintegers
Use the [`uint()` function](/flux/v0.x/stdlib/universe/uint/) to convert
the following [basic types](/flux/v0.x/data-types/basic/) to uintegers:
- **string**: returns the uinteger equivalent of the numeric string (`[0-9]`)
- **bool**: returns `1` for `true` or `0` for `false`
- **duration**: returns the number of nanoseconds in the duration
- **time**: returns the equivalent [nanosecond epoch timestamp](/influxdb/cloud/reference/glossary/#unix-timestamp)
- **float**: truncates the float value at the decimal and returns the uinteger equivalent
- **int**: returns the uinteger equivalent of the integer
```js
uint(v: "123")
// 123
uint(v: true)
// Returns 1
uint(v: 1d3h24m)
// Returns 98640000000000
uint(v: 2021-01-01T00:00:00Z)
// Returns 1609459200000000000
uint(v: 12.54)
// Returns 12
uint(v: -54321)
// Returns 18446744073709497295
```
{{% note %}}
#### Round float values before converting to uintegers
Being Flux _truncates_ the [float](/flux/v0.x/data-types/basic/float/) value at the decimal when converting to a uinteger, for example `12.54` to `12`, you may want to round float values to the nearest whole number `12.54` to `13` before converting. To do this:
1. Import the [`math` package](/flux/v0.x/stdlib/math/).
2. Use [`math.round()`](/flux/v0.x/stdlib/math/round/) to round the the float value
before converting it to a uinteger.
```js
import "math"
uint(v: math.round(x: 12.54))
// Returns 13
```
{{% /note %}}
### Convert columns to uintegers
Flux lets you iterate over rows in a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
and convert columns to uintegers.
**To convert the `_value` column to uintegers**, use the [`toUInt()` function](/flux/v0.x/stdlib/universe/touint/).
{{% note %}}
`toUInt()` only operates on the `_value` column.
{{% /note %}}
```js
data
|> toUInt()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | \_value _<span style="opacity:.5">(float)</span>_ |
| :------------------- | ------------------------------------------------: |
| 2021-01-01T00:00:00Z | 1.23 |
| 2021-01-01T02:00:00Z | 4.56 |
| 2021-01-01T03:00:00Z | -7.89 |
| 2021-01-01T04:00:00Z | 10.11 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | \_value _<span style="opacity:.5">(uint)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | 1 |
| 2021-01-01T02:00:00Z | 4 |
| 2021-01-01T03:00:00Z | 18446744073709551609 |
| 2021-01-01T04:00:00Z | 10 |
{{% /flex-content %}}
{{< /flex >}}
**To convert any column to uintegers**:
1. Use [`map()`](/flux/v0.x/stdlib/universe/map/) to iterate over and rewrite rows.
2. Use [`uint()`](/flux/v0.x/stdlib/universe/uint/) to convert columns values to uintegers.
```js
data
|> map(fn: (r) => ({ r with uid: uint(v: r.uid) }))
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| \_time | index _<span style="opacity:.5">(string)</span>_ |
| :------------------- | -----------------------------------------------: |
| 2021-01-01T00:00:00Z | 100010024 |
| 2021-01-01T02:00:00Z | 100050213 |
| 2021-01-01T03:00:00Z | 200130763 |
| 2021-01-01T04:00:00Z | 101420099 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| \_time | index _<span style="opacity:.5">(uint)</span>_ |
| :------------------- | ---------------------------------------------: |
| 2021-01-01T00:00:00Z | 100010024 |
| 2021-01-01T02:00:00Z | 100050213 |
| 2021-01-01T03:00:00Z | 200130763 |
| 2021-01-01T04:00:00Z | 101420099 |
{{% /flex-content %}}
{{< /flex >}}
## Operate on uintegers
- [Perform arithmetic operations on uintegers](#perform-arithmetic-operations-on-uintegers)
- [Compare uintegers](#compare-uintegers)
### Perform arithmetic operations on uintegers
To perform operations like adding, subtracting, multiplying, or dividing uintegers,
use [Flux arithmetic operators](/flux/v0.x/spec/operators/#arithmetic-operators).
Operands must be the same type.
The operation returns an uinteger.
{{% note %}}
When operating with uinteger operands, fractional results are truncated at the decimal.
{{% /note %}}
```js
uint(v: 1) + uint(v: 45)
// Returns 46
uint(v: 1) - uint(v: 45)
// Returns 18446744073709551572
uint(v: 12) * uint(v: 100)
// Returns 1200
uint(v: 100) / uint(v: 200)
// Returns 0
uint(v: 10) ^ uint(v: 2)
// Returns 100
```
### Compare uintegers
Use [Flux comparison operators](/flux/v0.x/spec/operators/#comparison-operators)
to compare uintegers.
Operands must be the same type.
The operation returns a boolean.
```js
uint(v: 12345600) == uint(v: 12345601)
// Returns false
uint(v: 2) > uint(v: -2)
// Returns false
```

View File

@ -0,0 +1,20 @@
---
title: Work with composite data types
seotitle: Work with composite Flux data types
list_title: Composite types
description: >
Flux **composite types** are types constructed from basic types.
Flux supports the following composite types: record, array, dictionary, function.
menu:
flux_0_x:
name: Composite types
parent: Work with Flux types
weight: 101
---
Flux **composite types** are types constructed from basic types.
Flux supports the following composite types:
{{< children type="anchored-list" >}}
{{< children type="articles" readmore=true >}}

View File

@ -0,0 +1,135 @@
---
title: Work with arrays
seotitle: Work with arrays in Flux
list_title: Array
description: >
An **array** type is an ordered sequence of values of the same type.
Learn how to work with arrays in Flux.
menu:
flux_0_x:
name: Array
parent: Composite types
weight: 202
flux/v0.x/tags: ["composite types", "data types"]
related:
- /flux/v0.x/stdlib/universe/length/
- /flux/v0.x/stdlib/array/
list_code_example: |
```js
["1st", "2nd", "3rd"]
[1.23, 4.56, 7.89]
[10, 25, -15]
```
---
An **array** type is an ordered sequence of values of the same type.
- [Array syntax](#array-syntax)
- [Reference values in an array](#reference-values-in-an-array)
- [Operate on arrays](#operate-on-arrays)
## Array syntax
An array literal contains a sequence of values (also known as elements) enclosed
in square brackets (`[]`).
Values are comma-separated and must be the same type.
##### Example arrays
```js
["1st", "2nd", "3rd"]
[1.23, 4.56, 7.89]
[10, 25, -15]
```
## Reference values in an array
Use **bracket notation** to reference reference a value in an array.
Flux arrays use **zero-based indexing**.
Provide the index of the value to reference.
```js
arr = ["1st", "2nd", "3rd"]
arr[0]
// Returns 1st
arr[2]
// Returns 3rd
```
## Operate on arrays
- [Iterate over an array](#iterate-over-an-array)
- [Check if a value exists in an array](#check-if-a-value-exists-in-an-array)
- [Get the length of an array](#get-the-length-of-an-array)
- [Create a stream of tables from an array](#create-a-stream-of-tables-from-an-array)
- [Compare arrays](#compare-arrays)
### Iterate over an array
{{% note %}}
Flux currently does not provide a way to iterate over an array.
{{% /note %}}
### Check if a value exists in an array
Use the [`contains` function](/flux/v0.x/stdlib/universe/contains/) to check if
a value exists in an array.
```js
names = ["John", "Jane", "Joe", "Sam"]
contains(value: "Joe", set: names)
// Returns true
```
### Get the length of an array
Use the [`length` function](/flux/v0.x/stdlib/universe/length/) to get the
length of an array (number of elements in the array).
```js
names = ["John", "Jane", "Joe", "Sam"]
length(arr: names)
// Returns 4
```
### Create a stream of tables from an array
1. Import the [`array` package](/flux/v0.x/stdlib/array/).
2. Use [`array.from()`](/flux/v0.x/stdlib/array/from/) to return a
[stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables).
The input array must be an array of [records](/flux/v0.x/data-types/composite/record/).
Each key-value pair in the record represents a column and its value.
```js
import "array"
arr = [
{fname: "John", lname: "Doe", age: "37"},
{fname: "Jane", lname: "Doe", age: "32"},
{fname: "Jack", lname: "Smith", age: "56"}
]
array.from(rows: arr)
```
##### Output
| fname | lname | age |
| :---- | :---- | --: |
| John | Doe | 37 |
| Jane | Doe | 32 |
| Jack | Smith | 56 |
### Compare arrays
Use the `==` [comparison operator](/flux/v0.x/spec/operators/#comparison-operators)
to check if two arrays are equal.
Equality is based on values, their type, and order.
```js
[1,2,3,4] == [1,3,2,4]
// Returns false
[12300.0, 34500.0] == [float(v: "1.23e+04"), float(v: "3.45e+04")]
// Returns true
```

View File

@ -0,0 +1,135 @@
---
title: Work with dictionaries
seotitle: Work with dictionaries in Flux
list_title: Dictionary
description: >
A **dictionary** type is a collection of key-value pairs with keys of the same
type and values of the same type.
Learn how to work with dictionaries in Flux.
menu:
flux_0_x:
name: Dictionary
parent: Composite types
weight: 203
flux/v0.x/tags: ["composite types", "data types"]
related:
- /flux/v0.x/stdlib/dict/
list_code_example: |
```js
[0: "Sun", 1: "Mon", 2: "Tue"]
["red": "#FF0000", "green": "#00FF00", "blue": "#0000FF"]
[1.0: {stable: 12, latest: 12}, 1.1: {stable: 3, latest: 15}]
```
---
A **dictionary** type is a collection of key-value pairs with keys of the same
type and values of the same type.
- [Dictionary syntax](#dictionary-syntax)
- [Reference dictionary values](#reference-dictionary-values)
- [Operate on dictionaries](#operate-on-dictionaries)
## Dictionary syntax
A **dictionary** literal contains a set of key-value pairs (also known as elements)
enclosed in square brackets (`[]`).
Elements are comma-delimited.
Keys must all be the same type.
Values must all be the same type.
Keys are associated to values by a colon (`:`).
##### Example dictionaries
```js
[0: "Sun", 1: "Mon", 2: "Tue"]
["red": "#FF0000", "green": "#00FF00", "blue": "#0000FF"]
[1.0: {stable: 12, latest: 12}, 1.1: {stable: 3, latest: 15}]
```
## Reference dictionary values
Flux dictionaries are **key-indexed**.
To reference values in a dictionary:
1. Import the [`dict` package](/flux/v0.x/stdlib/dict/).
2. Use [`dict.get()`](/flux/v0.x/stdlib/dict/get/) and provide the following parameters:
- **dict**: Dictionary to reference
- **key**: Key to reference
- **default**: Default value to return if the key does not exist
```js
import "dict"
positions = [
"Manager": "Jane Doe",
"Asst. Manager": "Jack Smith",
"Clerk": "John Doe"
]
dict.get(dict: positions, key: "Manager", default: "Unknown position")
// Returns Jane Doe
dict.get(dict: positions, key: "Teller", default: "Unknown position")
// Returns Unknown position
```
## Operate on dictionaries
- [Create a dictionary from a list](#create-a-dictionary-from-a-list)
- [Insert a key-value pair into a dictionary](#insert-a-key-value-pair-into-a-dictionary)
- [Remove a key-value pair from a dictionary](#remove-a-key-value-pair-from-a-dictionary)
### Create a dictionary from a list
1. Import the [`dict` package](/flux/v0.x/stdlib/dict/).
2. Use [`dict.fromList()`](/flux/v0.x/stdlib/dict/fromlist/) to create a dictionary
from an **[array](/flux/v0.x/data-types/composite/array/) of [records](/flux/v0.x/data-types/composite/record/)**.
Each record must have a **key** and **value** property.
```js
import "dict"
list = [
{key: "k1", value: "v1"},
{key: "k2", value: "v2"}
]
dict.fromList(pairs: list)
// Returns [k1: v1, k2: v2]
```
### Insert a key-value pair into a dictionary
1. Import the [`dict` package](/flux/v0.x/stdlib/dict/).
2. Use [`dict.insert()`](/flux/v0.x/stdlib/dict/insert/) to insert a key-value
pair into a dictionary. If the key already exists, it's overwritten with the new value.
```js
import "dict"
exampleDict = ["k1": "v1", "k2": "v2"]
dict.insert(
dict: exampleDict,
key: "k3",
value: "v3"
)
// Returns [k1: v1, k2: v2, k3: v3]
```
### Remove a key-value pair from a dictionary
1. Import the [`dict` package](/flux/v0.x/stdlib/dict/).
2. Use [`dict.remove()`](/flux/v0.x/stdlib/dict/remove/) to remove a key-value
pair from a dictionary.
```js
import "dict"
exampleDict = ["k1": "v1", "k2": "v2"]
dict.remove(
dict: exampleDict,
key: "k2"
)
// Returns [k1: v1]
```

View File

@ -0,0 +1,68 @@
---
title: Work with functions
seotitle: Work with functions in Flux
list_title: Function
description: >
A **function** type is a set of parameters that perform an operation.
Learn how to work with functions in flux.
menu:
flux_0_x:
name: Function
parent: Composite types
weight: 204
flux/v0.x/tags: ["composite types", "data types"]
related:
- /flux/v0.x/define-functions/
list_code_example: |
```js
() => 1
(a, b) => a + b
(a, b, c=2) => {
d = a + b
return d / c
}
```
---
A **function** type is a set of parameters that perform an operation.
- [Function syntax](#function-syntax)
- [Define functions](#define-functions)
## Function syntax
A Flux **function** literal contains the following:
- Zero or more parameters enclosed in parentheses (`()`)
- Parameters are comma separated
- Parameters must be named (no positional params)
- Optionally assign a default value for each parameter with the `=`
[assignment operator](/flux/v0.x/spec/operators/#assignment-operators).
Parameters without a default value require user input and are considered **required parameters**.
- `=>` [arrow operator](/flux/v0.x/spec/operators/#function-operators) to pass parameters into the function body.
- Function body to define function operations and return a response.
##### Example functions
```js
// Function that returns the value 1
() => 1
// Function that returns the sum of a and b
(a, b) => a + b
// Function with default values
(x=1, y=1) => x * y
// Function with a block body
(a, b, c) => {
d = a + b
return d / c
}
```
## Define functions
_For information about defining custom functions, see [Define custom functions](/flux/v0.x/define-functions/)._

View File

@ -0,0 +1,183 @@
---
title: Work with records
seotitle: Work with records in Flux
list_title: Record
description: >
A **record** type is a set of key-value pairs.
Learn how to work with record types in Flux.
menu:
flux_0_x:
name: Record
parent: Composite types
weight: 201
flux/v0.x/tags: ["composite types", "data types"]
list_code_example: |
```js
{foo: "bar", baz: 123.4, quz: -2}
{"Company Name": "ACME", "Street Address": "123 Main St.", id: 1123445}
```
---
A **record** type is a set of key-value pairs (also known as properties).
Keys (also known as labels) are strings.
Values can be any data type.
Each property can have a different value type.
- [Record syntax](#record-syntax)
- [Reference values in a record](#reference-values-in-a-record)
- [Operate on records](#operate-on-records)
## Record syntax
A **record** literal contains a set of key-value pairs (properties) enclosed in curly brackets (`{}`).
Properties are comma-delimitted.
**Property keys must be strings** and can optionally be enclosed in double quotes (`"`).
If a property key contains whitespace characters or only numeric characters,
you must enclose the property key in double quotes.
Property keys are associated to values by a colon (`:`).
**Values can be any type**.
##### Example records
```js
{foo: "bar", baz: 123.4, quz: -2}
{"Company Name": "ACME", "Street Address": "123 Main St.", id: 1123445}
```
## Reference values in a record
Flux records are **key-indexed**.
To reference values in a record, use **dot notation** or **bracket notation**
and specify the key to reference.
- [Dot notation](#dot-notation)
- [Bracket notation](#bracket-notation)
- [Reference nested records](#reference-nested-records)
- [Reference keys statically](#reference-keys-statically)
### Dot notation
Specify the record to access followed by a period (`.`) and the property key.
```js
c = {
name: "John Doe",
address: "123 Main St.",
id: 1123445
}
c.name
// Returns John Doe
c.id
// Returns 1123445
```
### Bracket notation
Specify the record to access followed by the property key enclosed in double
quotes and square brackets (`[""]`).
{{% note %}}
Use bracket notation to access keys with special or whitespace characters.
{{% /note %}}
```js
c = {
"Company Name": "ACME",
"Street Address": "123 Main St.",
id: 1123445
}
c["Company Name"]
// Returns ACME
c["id"]
// Returns 1123445
```
### Reference nested records
To reference nested records, use chained dot or bracket notation for each nested level.
```js
customer = {
name: "John Doe",
address: {
street: "123 Main St.",
city: "Pleasantville",
state: "New York"
}
}
customer.address.street
// Returns 123 Main St.
customer["address"]["city"]
// Returns Pleasantville
customer["address"].state
// Returns New York
```
### Reference keys statically
**Record keys can only be referenced statically**, meaning you cannot dynamically
specify a key to access. For example:
```js
key = "foo"
o = {foo: "bar", baz: 123.4}
o.key
// Error: type error: record is missing label key
```
_To dynamically reference keys in a composite type, consider using a
[dictionary](/flux/v0.x/data-types/composite/dict/)._
## Operate on records
- [Extend a record](#extend-a-record)
- [List keys in a record](#list-keys-in-a-record)
- [Compare records](#compare-records)
### Extend a record
Use the **`with` operator** to extend a record.
The `with` operator overwrites record properties if the specified keys exists or
adds the new properties if the keys do not exist.
```js
c = {
name: "John Doe",
id: 1123445
}
{c with spouse: "Jane Doe", pet: "Spot"}
// Returns {id: 1123445, name: John Doe, pet: Spot, spouse: Jane Doe}
```
### List keys in a record
1. Import the [`experimental` package](/flux/v0.x/stdlib/experimental/).
2. Use [`experimental.objectKeys`](/flux/v0.x/stdlib/experimental/objectkeys/)
to return an array of keys in a record.
```js
import "experimental"
c = {
name: "John Doe",
id: 1123445
}
experimental.objectKeys(o: c)
// Returns [name, id]
```
### Compare records
Use the `==` [comparison operator](/flux/v0.x/spec/operators/#comparison-operators)
to check if two records are equal.
Equality is based on keys, their values, and types.
```js
{id: 1, msg: "hello"} == {id: 1, msg: "goodbye"}
// Returns false
{foo: 12300.0, bar: 34500.0} == {bar: float(v: "3.45e+04"), foo: float(v: "1.23e+04")}
// Returns true
```

View File

@ -0,0 +1,144 @@
---
title: Work with regular expression types
seotitle: Work with Flux regular expression types
list_title: Regular expression types
description: >
Learn how to work with Flux regular expression types.
menu:
flux_0_x:
name: Regular expression types
parent: Work with Flux types
weight: 101
flux/v0.x/tags: ["regexp types", "data types"]
related:
- /flux/v0.x/stdlib/regexp/
---
A **regular expression** type represents a regular expression pattern.
**Type name**: `regexp`
- [Regular expression syntax](#regular-expression-syntax)
- [Use regular expression flags](#use-regular-expression-flags)
- [Use regular expressions in predicate expressions](#use-regular-expressions-in-predicate-expressions)
- [Convert a string to a regular expression](#convert-a-string-to-a-regular-expression)
- [Examples](#examples)
## Regular expression syntax
Flux uses the [Go regexp implementation and syntax](https://pkg.go.dev/regexp).
This syntax is similar to regular expressions in Perl, Python, and other languages.
Regular expression literals are enclosed in forward slash characters (`/`).
```js
/^[a-z0-9]{1,}$/
```
## Use regular expression flags
Flux supports the following regular expression flags:
| Flag | Description |
| :--- | :------------------------------------------------------------------------------ |
| i | case-insensitive |
| m | multi-line mode: `^` and `$` match begin/end line in addition to begin/end text |
| s | let `.` match `\n` |
| U | ungreedy: swap meaning of `x*` and `x*?`, `x+` and `x+?`, etc |
Include regular expression flags at the beginning of your regular expression pattern
enclosed in parentheses (`()`) and preceded by a question mark (`?`).
```js
/(?iU)foo*/
```
## Use regular expressions in predicate expressions
To use regular expressions in [predicate expressions](/flux/v0.x/get-started/syntax-basics/#predicate-expressions),
use the [`=~` and `!~` comparison operators](/flux/v0.x/spec/operators/#comparison-operators).
The right operand must be a string.
The left operand must be a regular expression.
```js
"abc" =~ /\w/
// Returns true
"z09se89" =~ /^[a-z0-9]{7}$/
// Returns true
"foo" !~ /^f/
// Returns false
"FOO" =~ /(?i)foo/
// Returns true
```
## Convert a string to a regular expression
1. Import the [`regexp` package](/flux/v0.x/stdlib/regexp/).
2. Use [`regexp.compile()`](/flux/v0.x/stdlib/regexp/compile) to compile a
string into a regular expression type.
```js
import "regexp"
regexp.compile(v: "^- [a-z0-9]{7}")
// Returns ^- [a-z0-9]{7} (regexp type)
```
## Examples
- [Replace all substrings that match a regular expression](#replace-all-substrings-that-match-a-regular-expression)
- [Return the first regular expression match in a string](#return-the-first-regular-expression-match-in-a-string)
- [Escape regular expression metacharacters in a string](#escape-regular-expression-metacharacters-in-a-string)
### Replace all substrings that match a regular expression
1. Import the [`regexp` package](/flux/v0.x/stdlib/regexp).
2. Use [`regexp.replaceAllString()`](/flux/v0.x/stdlib/regexp/replaceallstring/)
and provide the following parameters:
- **r**: regular expression
- **v**: string to search
- **t**: replacement for matches to **r**.
```js
import "regexp"
regexp.replaceAllString(
r: /a(x*)b/,
v: "-ab-axxb-",
t: "T"
)
// Returns "-T-T-"
```
### Return the first regular expression match in a string
1. Import the [`regexp` package](/flux/v0.x/stdlib/regexp).
2. Use [`regexp.findString()`](/flux/v0.x/stdlib/regexp/findstring/) to return
the first regular expression match in a string.
Provide the following parameters:
- **r**: regular expression
- **v**: string to search
```js
import "regexp"
regexp.findString(
r: /foo.?/,
v: "seafood fool"
)
// Returns "food"
```
### Escape regular expression metacharacters in a string
If a string contains regular expression metacharacters that should be evaluated
as literal characters, escape the metacharacters before converting the string
to a regular expression:
1. Import the [`regexp` package](/flux/v0.x/stdlib/regexp).
2. Use [`regexp.quoteMeta()`](/flux/v0.x/stdlib/regexp/quotemeta/)
and provide the string to escape regular expression metacharacters in:
```js
import "regexp"
regexp.quoteMeta(v: ".+*?()|[]{}^$")
// Returns "\.\+\*\?\(\)\|\[\]\{\}\^\$"
```

View File

@ -0,0 +1,14 @@
---
title: Work with union types
seotitle: Work with Flux union types
list_title: Union types
description: >
...
menu:
flux_0_x:
name: Union types
parent: Work with Flux types
weight: 101
flux/v0.x/tags: ["regexp types", "data types"]
draft: true
---

View File

@ -0,0 +1,285 @@
---
title: Define custom functions
seotitle: Define custom Flux functions
list_title: Define functions
description: >
Flux's functional syntax lets you define custom functions.
Learn the basics of creating your own functions.
menu:
flux_0_x:
name: Define functions
weight: 6
related:
- /flux/v0.x/data-types/composite/function/
---
Flux's functional syntax lets you define custom functions.
Learn the basics of creating your own functions.
###### On this page:
- [Function definition syntax](#function-definition-syntax)
- [Custom function examples](#custom-function-examples)
- [Create a custom transformation](#create-a-custom-transformation)
- [Custom transformation examples](#custom-transformation-examples)
- [Define functions with scoped variables](#define-functions-with-scoped-variables)
- [Example functions with scoped variables](#example-functions-with-scoped-variables)
## Function definition syntax
The basic syntax for defining functions in Flux is as follows:
```js
// Basic function definition syntax
functionName = (functionParameters) => functionBody
```
- **functionName**: Name to use to execute the function.
- **functionParameters**: Comma-separated list of parameters passed into the function.
- **functionBody**: Operations on function parameters.
### Define parameter defaults
Use the `=` assignment operator to assign a default value to function parameters
in your function definition:
```js
functionName = (param1=defaultVal1, param2=defaultVal2) => functionBody
```
Defaults are overridden by explicitly defining the parameter in the function call.
Parameters without default values are considered **required parameters**.
## Custom function examples
{{< expand-wrapper >}}
{{% expand "Square a number" %}}
```js
square = (n) => n * n
square(n:3)
// Returns 9
```
{{% /expand %}}
{{% expand "Multiple two values" %}}
```js
multiply = (x, y) => x * y
multiply(x: 2, y: 15)
// Returns 30
```
{{% /expand %}}
{{% expand "Calculate n to the p power (with default parameters)" %}}
```js
pow = (n, p=10) => n ^ p
pow(n: 2)
// Returns 1024
```
{{% /expand %}}
{{< /expand-wrapper >}}
## Create a custom transformation
A [transformation](/flux/v0.x/function-types/#transformations) is a function that
takes a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
as input, operates on the input, and then outputs a new stream of tables.
The [pipe-forward operator](/flux/v0.x/get-started/syntax-basics/#pipe-forward-operator) (`|>`)
pipes data from the previous identifier or function forward into a transformation.
To use piped-forward data, assign a function parameter to the
[pipe-receive operator](/flux/v0.x/spec/operators/#function-operators) (`<-`).
In the following example, the function `x()` receives piped-forwarded data and assigns it to the `t` parameter.
In the function body, `t` is piped forward into other operations to generate output.
```js
x = (t=<-) => t |> //...
```
### Custom transformation examples
{{< expand-wrapper >}}
{{% expand "Multiply values by x" %}}
#### Multiply values by x
The following example defines a `multByX` function that multiplies the `_value` column
of each input row by the `x` parameter.
The example uses the [`map()` function](/flux/v0.x/stdlib/universe/map/) to iterate over
each row, modify the `_value`, and then return the updated row.
##### Function definition
```js
multByX = (tables=<-, x) =>
tables
|> map(fn: (r) => ({ r with _value: r._value * x }))
```
##### Example usage
```js
data
|> multByX(x: 2.0)
```
{{< flex >}}
{{% flex-content %}}
###### Given the following input data:
| srcID | _field | _value |
| :---- | :----- | -----: |
| t1a | foo | 1.2 |
| t1a | foo | 3.4 |
| t1a | foo | 5.6 |
| srcID | _field | _value |
| :---- | :----- | -----: |
| t2b | foo | 0.8 |
| t2b | foo | 1.9 |
| t2b | foo | 2.7 |
{{% /flex-content %}}
{{% flex-content %}}
###### The example above returns:
| srcID | _field | _value |
| :---- | :----- | -----: |
| t1a | foo | 2.4 |
| t1a | foo | 6.8 |
| t1a | foo | 11.2 |
| srcID | _field | _value |
| :---- | :----- | -----: |
| t2b | foo | 1.6 |
| t2b | foo | 3.8 |
| t2b | foo | 5.4 |
{{% /flex-content %}}
{{< /flex >}}
{{% /expand %}}
{{% expand "Calculate speed" %}}
#### Calculate speed
The following example defines a `speed` function that calculates speed using an
`elapsed` and `distance` column in input tables.
The example uses the [`map()` function](/flux/v0.x/stdlib/universe/map/) to iterate over
each row, calculate the speed per specified unit of distance, and then return
the updated row with a new `speed` column.
##### Function definition
```js
speed = (tables=<-, unit="m") =>
tables
|> map(fn: (r) => {
elapsedHours = float(v: int(v: duration(v: r.elapsed))) / float(v: int(v: 1h))
distance = float(v: r.distance)
speed = distance / elapsedHours
return { r with speed: "${speed} ${unit}ph" }
})
```
##### Example usage
```js
data
|> speed()
```
{{< flex >}}
{{% flex-content %}}
##### Given the following input data:
| id | elapsed | distance |
| :-- | ------: | -------: |
| t1 | 1h15m | 101 |
| t2 | 1h32m | 138 |
| t3 | 56m | 112 |
{{% /flex-content %}}
{{% flex-content %}}
##### The example above returns:
| id | elapsed | distance | speed |
| :-- | ------: | -------: | -------: |
| t1 | 1h15m | 101 | 88.8 mph |
| t2 | 1h32m | 138 | 90 mph |
| t3 | 56m | 112 | 120 mph |
{{% /flex-content %}}
{{< /flex >}}
{{% /expand %}}
{{< /expand-wrapper >}}
## Define functions with scoped variables
To create custom functions with variables scoped to the function,
1. Enclose your [function body](#function-definition-syntax) in a
[block (`{}`)](/flux/v0.x/spec/blocks/).
2. Use a `return` statement to return a specific variable.
```js
functionName = (param) => {
exampleVar = "foo"
return exampleVar
}
```
### Example functions with scoped variables
{{< expand-wrapper >}}
{{% expand "Return an alert level based on a value" %}}
#### Return an alert level based on a value
The following function uses conditional logic to return an alert level based on
a numeric input value:
```js
alertLevel = (v) => {
level = if float(v:v) >= 90.0 then "crit"
else if float(v:v) >= 80.0 then "warn"
else if float(v:v) >= 65.0 then "info"
else "ok"
return level
}
alertLevel(v: 87.3)
// Returns "warn"
```
{{% /expand %}}
{{% expand "Convert a HEX color code to a name" %}}
#### Convert a HEX color code to a name
The following function converts a hexadecimal (HEX) color code to the equivalent HTML color name.
The functions uses the [Flux dictionary package](/flux/v0.x/stdlib/dict/)
to create a dictionary of HEX codes and their corresponding names.
```js
import "dict"
hexName = (hex) => {
hexNames = dict.fromList(pairs: [
{key: "#00ffff", value: "Aqua"},
{key: "#000000", value: "Black"},
{key: "#0000ff", value: "Blue"},
{key: "#ff00ff", value: "Fuchsia"},
{key: "#808080", value: "Gray"},
{key: "#008000", value: "Green"},
{key: "#00ff00", value: "Lime"},
{key: "#800000", value: "Maroon"},
{key: "#000080", value: "Navy"},
{key: "#808000", value: "Olive"},
{key: "#800080", value: "Purple"},
{key: "#ff0000", value: "Red"},
{key: "#c0c0c0", value: "Silver"},
{key: "#008080", value: "Teal"},
{key: "#ffffff", value: "White"},
{key: "#ffff00", value: "Yellow"},
])
name = dict.get(dict: hexNames, key: hex, default: "No known name")
return name
}
hexName(hex: "#000000")
// Returns "Black"
hexName(hex: "#8b8b8b")
// Returns "No known name"
```
{{% /expand %}}
{{< /expand-wrapper >}}

View File

@ -0,0 +1,234 @@
---
title: Flux function types and categories
description: >
Flux functions each share a set of behaviors or traits that define how the function works.
View high-level function types and categories that represent distinct and important function behaviors.
menu:
flux_0_x_ref:
name: Function types & categories
weight: 10
related:
- /flux/v0.x/stdlib/
aliases:
- /influxdb/v2.0/reference/flux/functions/inputs
- /influxdb/v2.0/reference/flux/functions/built-in/inputs/
- /influxdb/v2.0/reference/flux/stdlib/built-in/inputs/
- /influxdb/cloud/reference/flux/stdlib/built-in/inputs/
- /influxdb/v2.0/reference/flux/functions/outputs
- /influxdb/v2.0/reference/flux/functions/built-in/outputs/
- /influxdb/v2.0/reference/flux/stdlib/built-in/outputs/
- /influxdb/cloud/reference/flux/stdlib/built-in/outputs/
- /influxdb/v2.0/reference/flux/functions/misc
- /influxdb/v2.0/reference/flux/functions/built-in/misc/
- /influxdb/v2.0/reference/flux/stdlib/built-in/misc/
- /influxdb/cloud/reference/flux/stdlib/built-in/misc/
- /influxdb/v2.0/reference/flux/functions/built-in/tests/
- /influxdb/v2.0/reference/flux/stdlib/built-in/tests/
- /influxdb/cloud/reference/flux/stdlib/built-in/tests/
- /influxdb/v2.0/reference/flux/functions/transformations
- /influxdb/v2.0/reference/flux/functions/built-in/transformations/
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/
- /influxdb/v2.0/reference/flux/functions/transformations/aggregates
- /influxdb/v2.0/reference/flux/functions/built-in/transformations/aggregates/
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/aggregates/
- /influxdb/v2.0/reference/flux/functions/transformations/selectors
- /influxdb/v2.0/reference/flux/functions/built-in/transformations/selectors/
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/selectors/
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/selectors/
- /influxdb/v2.0/reference/flux/functions/built-in/transformations/stream-table/
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/stream-table/
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/stream-table/
- /influxdb/v2.0/reference/flux/functions/transformations/type-conversions
- /influxdb/v2.0/reference/flux/functions/built-in/transformations/type-conversions/
- /influxdb/v2.0/reference/flux/stdlib/built-in/transformations/type-conversions/
- /influxdb/cloud/reference/flux/stdlib/built-in/transformations/type-conversions/
---
Flux functions share a set of behaviors or traits that define how the function works.
This types and categories lists below are not all-inclusive, but covers distinct
and important function behaviors.
- [Function types](#function-types)
- [Function categories](#function-categories)
---
## Function types
- [Inputs](#inputs)
- [Outputs](#outputs)
- [Transformations](#transformations)
- [Aggregates](#aggregates)
- [Selectors](#selectors)
- [Dynamic queries](#dynamic-queries)
---
### Inputs
Flux input functions return data from data sources.
The following input functions are available:
{{< list-all-functions filters="inputs" >}}
---
### Outputs
Flux output functions yield results or send data to a specified output destination.
The following output functions are are available:
{{< list-all-functions filters="outputs" >}}
---
### Transformations
Flux transformations take a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
as input, transform the data in some way, and output a stream of tables.
Transformations cover a broad range of functions, but the following categorizations
highlight important behaviors associated with specific transformation functions.
- [Aggregates](#aggregates)
- [Selectors](#selectors)
{{% note %}}
##### aggregateWindow helper function
The [`aggregateWindow()` function](/flux/v0.x/stdlib/universe/aggregatewindow)
windows or groups data by time and applies an aggregate or selector function
to input tables.
**All aggregate and selector functions** work with `aggregateWindow()`.
{{% /note %}}
#### Aggregates
Flux aggregate functions are [transformations](#transformations) aggregate values
from input tables in some way.
Output tables contain a single row with the aggregated value.
Aggregate transformations output a table for every input table they receive.
Each output table from an aggregate function will:
- Contain a single record.
- Have the same [group key](/flux/v0.x/get-started/data-model/#group-key) as the input table.
- Contain the an aggregated column.
The column label will be the same as the input table.
The column data type depends on the specific aggregate operation.
The value of the column will be `null` if the input table is empty or the input
column has only `null` values.
- Drop all columns that are:
- not in the group key
- not the aggregated column
**The following aggregate functions are available:**
{{< list-all-functions filters="aggregates" >}}
##### Aggregate selectors
The following functions are both aggregates and selectors.
Each returns `n` values after performing an aggregate operation.
They are categorized as [selector functions](#selectors) in this documentation:
- [highestAverage()](/flux/v0.x/stdlib/universe/highestaverage)
- [highestCurrent()](/flux/v0.x/stdlib/universe/highestcurrent)
- [highestMax()](/flux/v0.x/stdlib/universe/highestmax)
- [lowestAverage()](/flux/v0.x/stdlib/universe/lowestaverage)
- [lowestCurrent()](/flux/v0.x/stdlib/universe/lowestcurrent)
- [lowestMin()](/flux/v0.x/stdlib/universe/lowestmin)
#### Selectors
Flux selector functions are [transformations](#transformations) that return one
or more record per input table.
Each output table from a selector function will:
- Contain one or more unmodified records.
- Have the same [group key](/flux/v0.x/get-started/data-model/#group-key) as the input table.
**The following selector functions are available:**
{{< list-all-functions filters="selectors" >}}
##### Selectors and aggregates
The following functions can be used as both selectors or aggregates, but they are
categorized as [aggregate functions](#aggregates) in this documentation:
- [median()](/flux/v0.x/stdlib/universe/median)
- [quantile()](/flux/v0.x/stdlib/universe/quantile)
---
### Dynamic queries
Flux dynamic query functions extract a table from a stream of tables and access its
columns and records.
For recommended usage, see [Extract scalar values](/influxdb/cloud/query-data/flux/scalar-values/).
{{< list-all-functions filters="dynamic queries" >}}
---
## Function categories
The following categories represent high-level function behaviors.
- [Filters](#filters)
- [Type conversions](#type-conversions)
- [Tests](#tests)
- [Date/time](#datetime)
- [Metadata](#metadata)
- [Notification endpoints](#notification-endpoints)
- [Geotemporal](#geotemporal)
### Filters
Filter functions iterate over and evaluate each input row to see if it matches
specified conditions.
Rows that do not match the specified conditions are dropped from the output.
The following filter functions are available:
{{< list-all-functions filters="filters" >}}
---
### Type conversions
Flux type conversion functions convert scalar values or columns to a specific data type.
The following type conversion functions are available:
{{< list-all-functions filters="type-conversions" >}}
---
### Tests
Flux testing functions test various aspects of data.
Tests return either `true` or `false`, a transformed stream of tables, or, upon failure, an error.
The following testing functions are available:
{{< list-all-functions filters="tests" >}}
---
### Date/time
Flux date/time functions return or operate on [time](/flux/v0.x/data-types/basic/time/)
or [duration](/flux/v0.x/spec/types/#duration-types) values.
The following data/time functions are available:
{{< list-all-functions filters="date/time" >}}
---
### Metadata
Flux metadata functions return metadata from the input stream or from an underlying data source.
The following metadata functions are available:
{{< list-all-functions filters="metadata" >}}
---
### Notification endpoints
Flux notification endpoint functions send notifications to external endpoints or services.
The following notification endpoint functions are available:
{{< list-all-functions filters="notification endpoints" >}}
---
### Geotemporal
Flux geotemporal functions are designed to work with geotemporal data (geographic location over time).
The following geotemporal functions are available:
{{< list-all-functions filters="geotemporal" >}}

View File

@ -0,0 +1,87 @@
---
title: Get started with Flux
description: >
Get started with Flux by learning important concepts of the Flux language.
menu:
flux_0_x:
name: Get started
weight: 1
---
Flux is a **functional data scripting** language designed to unify querying,
processing, analyzing, and acting on data into a single syntax.
## Flux overview
To understand how Flux works conceptually, consider the process of treating water.
Water is pulled from a source, limited by demand, piped through a series of stations
to modify (remove sediment, purify, and so on), and delivered in a consumable state.
<div class="flux-water-diagram"></div>
## Basic Flux query
Like treating water, a Flux query does the following:
1. Retrieves a specified amount of data from a source.
2. Filters data based on time or column values.
3. Processes and shapes data into expected results.
4. Returns the result.
To see how to retrieve data from a source, select the data source: InfluxDB, CSV, or PostgreSQL.
{{< code-tabs-wrapper >}}
{{% code-tabs %}}
[InfluxDB](#)
[CSV](#)
[PostgreSQL](#)
{{% /code-tabs %}}
{{% code-tab-content %}}
```js
from(bucket: "example-bucket")
|> range(start: -1d)
|> filter(fn: (r) => r._measurement == "example-measurement")
|> mean()
|> yield(name: "_results")
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```js
import "csv"
csv.from(file: "path/to/example/data.csv")
|> range(start: -1d)
|> filter(fn: (r) => r._measurement == "example-measurement")
|> mean()
|> yield(name: "_results")
```
{{% /code-tab-content %}}
{{% code-tab-content %}}
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost",
query:"SELECT * FROM TestTable"
)
|> filter(fn: (r) => r.UserID == "123ABC456DEF")
|> mean(column: "purchase_total")
|> yield(name: "_results")
```
{{% /code-tab-content %}}
{{< /code-tabs-wrapper >}}
Each example includes the following functions (in the order listed):
- [`from()`](/flux/v0.x/stdlib/influxdata/influxdb/from/) to retrieve data from the data source.
- [Pipe-forward operator (`|>`)](/flux/v0.x/get-started/syntax-basics/#pipe-forward-operator)
to send the output of each function to the next function as input.
- [`range()`](/flux/v0.x/stdlib/universe/range/), [`filter()`](/flux/v0.x/stdlib/universe/filter/),
or both to filter data based on column values.
- [`mean()`](/flux/v0.x/stdlib/universe/mean/) to calculate the average of values
returned from the data source.
- [`yield()`](/flux/v0.x/stdlib/universe/yield/) to yield results to the user.
_For detailed information about basic Flux queries,
see [Flux query basics](/flux/v0.x/get-started/query-basics/)._
{{< page-nav next="/flux/v0.x/get-started/data-model/" >}}

View File

@ -0,0 +1,105 @@
---
title: Flux data model
description: >
...
menu:
flux_0_x:
name: Data model
parent: Get started
weight: 101
---
To get the most out of using Flux to process your data, you must understand
how Flux structures and operates on data.
The **Flux data model** comprises the following:
- [Stream of tables](#stream-of-tables)
- [Table](#table)
- [Column](#column)
- [Row](#row)
- [Group key](#group-key)
{{< flux/data-model >}}
#### Stream of tables
A **stream of tables** is a collection of zero or more [tables](#table).
Data sources return results as a stream of tables.
#### Table
A **table** is a collection of [columns](#column) partitioned by [group key](#group-key).
#### Column
A **column** is a collection of values of the same [basic type](#)
that contains one value for each [row](#row).
#### Row
A **row** is a collection of associated [column](#column) values.
#### Group key
A **group key** defines which columns and specific column values to include in a table.
All rows in a table contain the same values in group key columns.
All tables in a stream of tables have a unique group key, but group key
modifications are applied to a stream of tables.
##### Example group keys
Group keys contain key-value pairs, where each key represents a column name and
each value represents the column value included in the table.
The following are examples of group keys in a stream of tables with three separate tables.
Each group key represents a table containing data for a unique location:
```
[_measurement: "production", facility: "us-midwest", _field: "apq"]
[_measurement: "production", facility: "eu-central", _field: "apq"]
[_measurement: "production", facility: "ap-east", _field: "apq"]
```
An **empty group key** groups all data in a stream of tables into a single table.
_For an example of how group keys work, see the [Table grouping example](#table-grouping-example) below._
{{% note %}}
#### Data sources determine data structure
The Flux data model is separate from the queried data source model.
Queried sources return data structured into columnar tables.
The table structure and columns included depends on the data source.
For example, InfluxDB returns data grouped by [series](/{{< latest "influxdb" >}}/reference/glossary/#series),
so each table in the returned stream of tables represents a unique series.
However, [SQL data sources](/flux/v0.x/stdlib/sql/from/) return a stream of tables
with a single table and an empty group key.
{{% /note %}}
## Operate on tables
At its core, Flux operates on tables.
Flux [transformations](/flux/v0.x/function-types/#transformations) take a stream
of tables as input, but operate on each table individually.
For example, aggregate transformations like [`sum()`](/flux/v0.x/stdlib/universe/sum/),
output a stream of tables containing one table for each corresponding input table:
{{< flux/table-ops >}}
## Restructure tables
All tables in a stream of tables are defined by their [group key](#group-key).
To change how data is partitioned or grouped into tables, use functions such as
[`group()`](/flux/v0.x/stdlib/universe/group/) or [`window()`](/flux/v0.x/stdlib/universe/window/)
to modify group keys in a stream of tables.
```js
data
|> group(columns: ["foo", "bar"], mode: "by")
```
### Table grouping example
The tables below represent data returned from InfluxDB with the following schema:
- `example` measurement
- `loc` tag with two values
- `sensorID` tag with two values
- `temp` and `hum` fields
To modify the group key and see how the sample data is partitioned into new tables,
select columns to group by:
{{< flux/group-key-demo >}}
{{< page-nav prev="/flux/v0.x/get-started/" next="/flux/v0.x/get-started/syntax-basics/" >}}

View File

@ -0,0 +1,197 @@
---
title: Flux query basics
description: >
View basic concepts and steps to use when querying data with Flux.
menu:
flux_0_x:
name: Query basics
parent: Get started
weight: 103
---
Most Flux queries follow the same basic structure.
Familiarize yourself with the basic concepts and steps to use when querying data with Flux.
- [Basic query structure](#basic-query-structure)
- [Write a basic query](#write-a-basic-query)
## Basic query structure
The majority of basic Flux queries include the following steps:
- [Source](#source)
- [Filter](#filter)
- [Shape](#shape-data)
- [Process](#process)
```js
from(bucket: "example-bucket") // ── Source
|> range(start: -1d) // ── Filter on time
|> filter(fn: (r) => r._field == "foo") // ── Filter on column values
|> group(columns: ["sensorID"]) // ── Shape
|> mean() // ── Process
```
### Source
Flux [input functions](/flux/v0.x/function-types/#inputs) retrieve data from a data source.
All input functions return a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables).
Flux supports multiple data sources including, time series databases (such as **InfluxDB** and **Prometheus**),
relational databases (such as **MySQL** and **PostgreSQL**), CSV, and more.
- For more information about supported data sources, see [Query data sources](/flux/v0.x/query-data/).
- For a list of input functions, see [Function types and categories Inputs](/flux/v0.x/function-types/#inputs).
### Filter
Filter functions iterate over and evaluate each input row to see if it matches
specified conditions.
Rows that meet the conditions are included in the function output.
Rows that do not meet the specified conditions are dropped.
Flux provides the following primary filter functions:
- [`range()`](/flux/v0.x/stdlib/universe/range/): filter data based on time.
- [`filter()`](/flux/v0.x/stdlib/universe/filter/): filter data based on column values.
`filter()` uses a [predicate function](/flux/v0.x/get-started/syntax-basics/#predicate-functions) defined in the
`fn` parameter to evaluate input rows.
Each row is passed into the predicate function as a **record**, `r`, containing
key-value pairs for each column in the row.
Other filter functions are also available.
For more information, see [Function types and categories Filters](/flux/v0.x/function-types/#filters).
### Shape data
Many queries need to modify the structure of data to prepare it for processing.
Common data-shaping tasks include [regrouping data](/flux/v0.x/get-started/data-model/#restructure-tables)
by column values or by time or pivoting column values into rows.
Functions that reshape data include the following:
- [`group()`](/flux/v0.x/stdlib/universe/group/): modify group keys
- [`window()`](/flux/v0.x/stdlib/universe/window/): modify `_start` and `_stop` values of rows to group data by time
- [`pivot()`](/flux/v0.x/stdlib/universe/pivot/): pivot column values into rows
- [`drop()`](/flux/v0.x/stdlib/universe/drop/): drop specific columns
- [`keep()`](/flux/v0.x/stdlib/universe/keep/): keep specific columns and drop all others
### Process
Processing data can take on many forms, and includes the following types of operations:
- **Aggregate data**: aggregate all rows of an input table into a single row.
For information, see [Function types and categories - Aggregates](/flux/v0.x/function-types/#aggregates).
- **Select specific data points**: return specific rows from each input table.
For example, return the first or last row, the row with the highest or lowest value, and more.
For information, see [Function types and categories - Selectors](/flux/v0.x/function-types/#selectors).
- **Rewrite rows**: use [`map()`](/flux/v0.x/stdlib/universe/map/) to rewrite each input row.
Tranform values with mathematic operations, process strings, dynamically add new columns, and more.
- **Send notifications**: evaluate data and use Flux notification endpoint functions
to send notifications to external services.
For information, see [Function types and categories- Notification endpoints](/flux/v0.x/function-types/#notification-endpoints).
{{% note %}}
#### aggregateWindow helper function
[`aggregateWindow()`](/flux/v0.x/stdlib/universe/aggregatewindow/) is a helper function
that both **shapes and processes data**.
The function windows and groups data by time, and then applies an [aggregate](/flux/v0.x/function-types/#aggregates)
or [selector](/flux/v0.x/function-types/#selectors) function to the restructured tables.
{{% /note %}}
---
## Write a basic query
Use [InfluxDB sample data](/{{< latest "influxdb" >}}/reference/sample-data/) to
write a basic Flux query that queries data, filters the data by time and column values,
and then applies an [aggregate](/flux/v0.x/function-types/#aggregates).
{{% note %}}
Use the [InfluxDB Data Explorer](/influxdb/cloud/query-data/execute-queries/data-explorer/)
or the [Flux REPL](/{{< latest "influxdb" >}}/tools/repl/#build-the-repl)
to build and execute the following basic query.
{{% /note %}}
1. Import the [`influxdata/influxdb/sample` package](/flux/v0.x/stdlib/influxdata/influxdb/sample/)
and use the [`sample.data()` function](/flux/v0.x/stdlib/influxdata/influxdb/sample/data/)
to load the `airSensor` sample dataset.
```js
import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
```
{{% note %}}
`sample.data()` returns data as if it was queried from InfluxDB.
To actually query data from InfluxDB, replace `sample.data()` with the
[`from()` function](/flux/v0.x/stdlib/influxdata/influxdb/from/).
{{% /note %}}
2. Pipe the returned data forward into [`range()`](/flux/v0.x/stdlib/universe/range/)
to filter the data by time.
Return data from the last hour.
```js
import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
|> range(start: -1h)
```
3. Use [`filter()`](/flux/v0.x/stdlib/universe/filter/) to filter rows based on
column values.
In this example, return only rows that include values for the `co` field.
The field name is stored in the `_field` column.
```js
import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
|> range(start: -1h)
|> filter(fn: (r) => r._field == "co")
```
4. Use [`mean()`](/flux/v0.x/stdlib/universe/mean/) to calculate the average value
in each input table.
Because InfluxDB groups data by [series](/influxdb/cloud/reference/glossary/#series),
`mean()` returns a table for each unique `sensor_id` containing a single row
with the average value in the `_value` column.
```js
import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
|> range(start: -1h)
|> filter(fn: (r) => r._field == "co")
|> mean()
```
5. Use [`group()`](/flux/v0.x/stdlib/universe/group) to [restructure tables](/flux/v0.x/get-started/data-model/#restructure-tables)
into a single table:
```js
import "influxdata/influxdb/sample"
sample.data(set: "airSensor")
|> range(start: -1h)
|> filter(fn: (r) => r._field == "co")
|> mean()
|> group()
```
Results from this basic query should be similar to the following:
{{% note %}}
`_start` and `_stop` columns have been omitted.
{{% /note %}}
| _field | _measurement | sensor_id | _value |
| :----: | :----------: | :-------: | ------------------: |
| co | airSensors | TLM0100 | 0.42338714381053716 |
| co | airSensors | TLM0101 | 0.4223251339463061 |
| co | airSensors | TLM0102 | 0.8543452859060252 |
| co | airSensors | TLM0103 | 0.2782783780205422 |
| co | airSensors | TLM0200 | 4.612143110484339 |
| co | airSensors | TLM0201 | 0.297474366047375 |
| co | airSensors | TLM0202 | 0.3336370208486757 |
| co | airSensors | TLM0203 | 0.4948166816959906 |
{{< page-nav prev="/flux/v0.x/get-started/syntax-basics/" >}}

View File

@ -0,0 +1,352 @@
---
title: Flux syntax basics
description: >
Learn the basic elements of Flux syntax with examples from real-world applications.
menu:
flux_0_x:
name: Syntax basics
parent: Get started
aliases:
- /influxdb/v2.0/query-data/get-started/syntax-basics/
- /influxdb/cloud/query-data/get-started/syntax-basics/
weight: 102
---
Flux, at its core, is a scripting language designed specifically for working with data.
This guide walks through how Flux handles a few simple expressions.
###### On this page
- [Pipe-forward operator](#pipe-forward-operator)
- [Simple expressions](#simple-expressions)
- [Predicate expressions](#predicate-expressions)
- [Variables](#variables)
- [Data types](#data-types)
- [Basic types](#basic-types)
- [Composite Types](#composite-types)
- [Records](#records)
- [Arrays](#arrays)
- [Dictionaries](#dictionaries)
- [Functions](#functions)
- [Regular expression types](#regular-expression-types)
- [Packages](#packages)
- [Examples of basic syntax](#examples-of-basic-syntax)
- [Define data stream variables](#define-data-stream-variables)
- [Define custom functions](#define-custom-functions)
## Pipe-forward operator
The **pipe-forward operator** (`|>`) sends the output of one function as input to the next function.
In the [water treatment metaphor](/flux/v0.x/get-started/#flux-overview),
the pipe-forward operator is the pipe that carries water (or data) through the pipeline.
```js
data
|> someFunction()
|> anotherFunction()
```
## Simple expressions
Flux supports basic expressions.
For example:
```js
1 + 1
// Returns 2
10 * 3
// Returns 30
(12.0 + 18.0) / (2.0 ^ 2.0) + (240.0 % 55.0)
// Returns 27.5
"John " + "Doe " + "is here!"
// Returns John Doe is here!
```
_For information about operator precedence, see
[Flux Operators Operator precedence](/flux/v0.x/spec/operators/#operator-precedence)._
## Predicate expressions
A predicate expression compares values using [comparison operators](/flux/v0.x/spec/operators/#comparison-operators), [logical operators](/flux/v0.x/spec/operators/#logical-operators), or both, and evalutes as `true` or `false`.
For example:
```js
"John" == "John"
// Returns true
41 < 30
// Returns false
"John" == "John" and 41 < 30
// Returns false
"John" == "John" or 41 < 30
// Returns true
```
Flux uses predicate expressions when [filtering data](/flux/v0.x/get-started/query-basics/#filter)
or in [conditional expressions](/flux/v0.x/spec/expressions/#conditional-expressions).
## Variables
Assign an expression to a variable using the
[assignment operator (`=`)](/flux/v0.x/spec/operators/#assignment-operators).
Use the name (identifier) of a variable to return its value:
```js
s = "foo" // string
i = 1 // integer
f = 2.0 // float (floating point number)
s // Returns foo
i // Returns 1
f // Returns 2.0
```
Variables can be assigned to any [Flux data type](/flux/v0.x/data-types/).
## Data types
Flux supports many data types grouped into the following categories:
- [Basic types](#basic-types)
- [Composite types](#composite-types)
- [Regular expression types](#regular-expression-types)
### Basic types
The following basic types can be represented with literal values:
- [Boolean](/flux/v0.x/data-types/basic/bool/)
- [Duration](/flux/v0.x/data-types/basic/duration/)
- [String](/flux/v0.x/data-types/basic/string/)
- [Time](/flux/v0.x/data-types/basic/time/)
- [Float](/flux/v0.x/data-types/basic/float/)
- [Integer](/flux/v0.x/data-types/basic/int/)
```js
// Boolean
true
// Duration
23h4m5s
// String
"foo"
// Time
2021-01-01T00:00:00Z
// Float
1.0
// Integer
1
```
The following basic types do not have a literal syntax, but can be created in other ways:
- [Bytes](/flux/v0.x/data-types/basic/bytes/)
- [Unsigned integers](/flux/v0.x/data-types/basic/uint/)
- [Nulls](/flux/v0.x/data-types/basic/null/)
### Composite Types
Flux [composite types](/flux/v0.x/data-types/composite/) are constructed from
Flux [basic types](#basic-types).
- [Records](#records)
- [Arrays](#arrays)
- [Dictionaries](#dictionaries)
- [Functions](#functions)
#### Records
A **record** is a collections of key-value pairs.
Each key is a string.
Each value can be a different data type.
```js
{name:"Jim", age: 42, "favorite color": "red"}
```
Use **dot notation** or **bracket notation** to access a properties of a record:
{{% note %}}
Use bracket notation to reference record properties with special or
white space characters in the property key.
{{% /note %}}
```js
o = {name:"Jim", age: 42, "favorite color": "red"}
o.name
// Returns Jim
o.age
// Returns 42
o["favorite color"]
// Returns red
```
_For more information, see [Work with records](/flux/v0.x/data-types/composite/record/)._
#### Arrays
An **array** is a collection of values of the same type.
```js
n = 4
l = [1,2,3,n]
l
// Returns [1, 2, 3, 4]
```
Use **bracket notation** to access a value at a specific index in an array:
```js
a = ["foo","bar","baz","quz"]
a[0]
// Returns foo
```
_For more information, see [Work with arrays](/flux/v0.x/data-types/composite/array/)._
#### Dictionaries
A **dictionary** is a collection of key-value pairs with keys of the same type
and values of the same type.
```js
[1: "foo", 2: "bar"]
```
Use [`dict.get()`](/flux/v0.x/stdlib/dict/get/) to access elements in a dictionary:
```js
import "dict"
d = [1: "foo", 2: "bar"]
dict.get(dict: d, key: "1", default: "")
// Returns foo
```
_For more information, see [Work with dictionaries](/flux/v0.x/data-types/composite/dict/)._
#### Functions
A **function** is a block of code that uses a set of parameters to perform an operation.
Functions can be named or anonymous.
Define parameters in parentheses (`()`) and pass parameters into an operation
with the [arrow operator (`=>`)](/flux/v0.x/spec/operators/#function-operators).
```js
square = (n) => n * n
square(n:3)
// Returns 9
```
{{% note %}}
Flux does not support positional parameters.
Parameters must always be named when calling a function.
{{% /note %}}
##### Predicate functions
Predicate functions use [predicate expressions](#predicate-expressions) to evaluate
input and return `true` or `false`. For example:
```js
examplePredicate = (v) => v == "foo"
examplePredicate(v: "foo")
// Returns true
examplePredicate(v: "bar")
// Returns false
```
For more information about working with functions, see:
- [Work with functions](/flux/v0.x/data-types/composite/function/)
- [Define custom functions](/flux/v0.x/define-functions/)
### Regular expression types
A **regular expression** is a regular expression pattern used to evaluate strings.
Use regular expressions in [predicate expressions](#predicate-expressions) or with
the [`regexp` package](/flux/v0.x/stdlib/regexp/).
```js
regex = /^foo/
"foo" =~ regex
// Returns true
"bar" =~ regex
// Returns false
```
## Packages
The [Flux standard library](/flux/v0.x/stdlib/) is organized into [packages](/flux/v0.x/spec/packages/)
that contain functions and package-specific options.
The [universe package](/flux/v0.x/stdlib/universe/) is loaded by default.
To load other packages, include an import statement for each package at the
beginning of your Flux script.
```js
import "array"
import "math"
import "influxdata/influxdb/sample"
```
## Examples of basic syntax
After reading the sections above, you can begin to apply these basic principles in real-world
use cases such as creating data stream variables, custom functions, and more.
- [Define data stream variables](#define-data-stream-variables)
- [Define custom functions](#define-custom-functions)
### Define data stream variables
A common use case for variable assignments in Flux is creating variables for one
or more input data streams.
The following example uses [`sample.data()`](/flux/v0.x/stdlib/influxdata/influxdb/sample/data/)
to query sample air sensor data and assigns different streams of data to unique variables.
```js
import "influxdata/influxdb/sample"
data = sample.data(set: "airSensor")
|> range(start: -15m)
|> filter(fn: (r) => r._measurement == "airSensors")
temperature =
data
|> filter(fn: (r) => r._field == "temperature")
humidity =
data
|> filter(fn: (r) => r._field == "humidity")
```
These variables can be used in other functions, such as `join()`, while keeping
the syntax minimal and flexible.
### Define custom functions
Create a function that returns the `N` number rows with the highest values in the `_value` column.
Pass the input stream (`<-`) and the number of results to return (`n`) into a custom function.
Use [`sort()`](/flux/v0.x/stdlib/universe/sort/) and [`limit()`](/flux/v0.x/stdlib/universe/limit/)
to find the top `n` results in the data set.
```js
topN = (tables=<-, n) =>
tables
|> sort(desc: true)
|> limit(n: n)
```
Use the custom function `topN` and the `humidity` data stream variable defined
above to return the top three data points in each input table.
```js
humidity
|> topN(n:3)
```
_For more information about creating custom functions, see [Define custom functions](/flux/v0.x/define-functions)._
{{< page-nav prev="/flux/v0.x/get-started/data-model/" next="/flux/v0.x/get-started/query-basics/" >}}

View File

@ -0,0 +1,13 @@
---
title: Query data sources
description: >
Query different data sources with Flux including InfluxDB, SQL databases, CSV, and Prometheus.
menu: flux_0_x
weight: 5
---
Query the following data sources with Flux:
{{< children type="anchored-list" >}}
{{< children readmore=true hr=true >}}

View File

@ -0,0 +1,73 @@
---
title: Query Google Cloud Bigtable
list_title: Google Cloud Bigtable
description: >
Use [`bigtable.from`](/flux/v0.x/stdlib/experimental/bigtable/from) to
query [Google Cloud Bigtable](https://cloud.google.com/bigtable/) with Flux.
menu:
flux_0_x:
name: Bigtable
parent: Query data sources
weight: 104
related:
- /flux/v0.x/stdlib/experimental/bigtable/from/
- https://cloud.google.com/bigtable/docs/access-control, Cloud Bigtable Access Control
- https://cloud.google.com/iam/docs/how-to, Google Cloud IAM How-to guides
- https://cloud.google.com/docs/authentication/production, Setting Up Authentication for Production Applications on Google Cloud
list_code_example: |
```js
import "experimental/bigtable"
bigtable.from(url: "http://example.com/metrics")
```
---
To query [Google Cloud Bigtable](https://cloud.google.com/bigtable/) with Flux:
1. Import the [`experimental/bigtable` package](/flux/v0.x/stdlib/experimental/bigtable/).
2. Use [`bigtable.from`](/flux/v0.x/stdlib/experimental/bigtable/from) and
provide the following parameters:
- **token**: Google Cloud IAM token
- **project**: Bigtable project ID
- **instance**: Bigtable instance ID
- **table**: Bigtable table to query
```js
import "experimental/bigtable"
bigtable.from(
token: "mySuPeRseCretTokEn",
project: "exampleProjectID",
instance: "exampleInstanceID",
table: "example-table"
)
```
## Results structure
`bigtable.from()` returns a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
with no grouping (all rows in a single table).
For more information about table grouping, see
[Flux data model - Restructure tables](/flux/v0.x/get-started/data-model/#restructure-tables).
## Store sensitive credentials as secrets
If using **InfluxDB Cloud** or **InfluxDB OSS 2.x**, we recommend storing Bigtable
connection credentials as [InfluxDB secrets](/influxdb/cloud/security/secrets/).
Use [`secrets.get()`](/flux/v0.x/stdlib/influxdata/influxdb/secrets/get/) to
retrieve a secret from the InfluxDB secrets API.
```js
import "experimental/bigtable"
import "influxdata/influxdb/secrets"
bigtable_token = secrets.get(key: "BIGTABLE_TOKEN")
bigtable_project = secrets.get(key: "BIGTABLE_PROJECT_ID")
bigtable_instance = secrets.get(key: "BIGTABLE_INSTANCE_ID")
bigtable.from(
token: bigtable_token,
project: bigtable_project,
instance: bigtable_instance,
table: "example-table"
)
```

View File

@ -0,0 +1,275 @@
---
title: Query CSV data sources
list_title: CSV
description: >
Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) and
[experimental `csv.from()`](/flux/v0.x/stdlib/experimental/csv/from/)
to query CSV data with Flux.
Query a CSV string, CSV file, or CSV data from a URL.
menu:
flux_0_x:
name: CSV
parent: Query data sources
weight: 103
related:
- /flux/v0.x/stdlib/csv/from/
- /flux/v0.x/stdlib/experimental/csv/from/, Experimental csv.from() function
- /influxdb/cloud/reference/syntax/annotated-csv/
list_code_example: |
```js
import "csv"
csvData = "
#group,false,false,true,true,true,false,false
#datatype,string,long,string,string,string,long,double
#default,_result,,,,,,
,result,table,dataset,metric,sensorID,timestamp,value
,,0,air-sensors,humidity,TLM0100,1627049400000000000,34.79
,,0,air-sensors,humidity,TLM0100,1627049700000000000,34.65
,,1,air-sensors,humidity,TLM0200,1627049400000000000,35.64
,,1,air-sensors,humidity,TLM0200,1627049700000000000,35.67
"
csv.from(csv: csvData)
```
---
Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) and
[experimental `csv.from()`](/flux/v0.x/stdlib/experimental/csv/from/)
to query CSV data with Flux.
Query a CSV string, CSV file, or CSV data from a URL.
Import the `csv` or `experimental/csv` package.
- [CSV parsing modes](#csv-parsing-modes)
- [Results structure](#results-structure)
- [Examples](#examples)
- [Query an annotated CSV string](#query-an-annotated-csv-string)
- [Query a raw CSV string](#query-a-raw-csv-string)
- [Query CSV data from a file](#query-csv-data-from-a-file)
- [Query CSV data from a URL](#query-csv-data-from-a-url)
## CSV parsing modes
`csv.from()` supports two CSV parsing modes:
- **annotations**: _(Default)_ Use CSV annotations to determine column data types and table grouping.
- **raw**: Parse all columns as strings and use the first row as the **header row**
and all subsequent rows as data.
{{% note %}}
When using the **annotations** parsing mode, CSV data must include all annotation rows
(`#datatype`, `#group`, and `#default`).
{{% /note %}}
## Results structure
The structure of results returned by `csv.from()` depends on the
[parsing mode](#csv-parsing-modes) used.
- **annotations**: `csv.from()` returns a stream of tables grouped by columns
defined as `true` in the `#group` annotation row.
- **raw**: `csv.from()`returns a stream of tables with no grouping (all rows are in a single table).
All data is formatted as strings.
## Examples
_If just getting started, use the [Flux REPL](/influxdb/cloud/tools/repl/) or the
[InfluxDB Data Explorer](/influxdb/cloud/query-data/execute-queries/data-explorer/)
to execute Flux queries._
- [Query an annotated CSV string](#query-an-annotated-csv-string)
- [Query a raw CSV string](#query-a-raw-csv-string)
- [Query CSV data from a file](#query-csv-data-from-a-file)
- [Query CSV data from a URL](#query-csv-data-from-a-url)
---
### Query an annotated CSV string
1. Import the [`csv` package](/flux/v0.x/stdlib/csv/).
2. Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) and the `csv` parameter to
specify the annotated CSV string to query.
#### Query
```js
import "csv"
csvData = "
#group,false,false,true,true,true,false,false
#datatype,string,long,string,string,string,long,double
#default,_result,,,,,,
,result,table,dataset,metric,sensorID,timestamp,value
,,0,air-sensors,humidity,TLM0100,1627049400000000000,34.79
,,0,air-sensors,humidity,TLM0100,1627049700000000000,34.65
,,1,air-sensors,humidity,TLM0200,1627049400000000000,35.64
,,1,air-sensors,humidity,TLM0200,1627049700000000000,35.67
,,2,air-sensors,temperature,TLM0100,1627049400000000000,71.84
,,2,air-sensors,temperature,TLM0100,1627049700000000000,71.87
,,3,air-sensors,temperature,TLM0200,1627049400000000000,74.10
,,3,air-sensors,temperature,TLM0200,1627049700000000000,74.17
"
csv.from(csv: csvData)
```
#### Results
| dataset | metric | sensorID | timestamp | value |
| :---------- | :------- | :------- | :------------------ | ----: |
| air-sensors | humidity | TLM0100 | 1627049400000000000 | 34.79 |
| air-sensors | humidity | TLM0100 | 1627049700000000000 | 34.65 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :------- | :------- | :------------------ | ----: |
| air-sensors | humidity | TLM0200 | 1627049400000000000 | 35.64 |
| air-sensors | humidity | TLM0200 | 1627049700000000000 | 35.67 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :---------- | :------- | :------------------ | ----: |
| air-sensors | temperature | TLM0100 | 1627049400000000000 | 71.84 |
| air-sensors | temperature | TLM0100 | 1627049700000000000 | 71.87 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :---------- | :------- | :------------------ | ----: |
| air-sensors | temperature | TLM0200 | 1627049400000000000 | 74.10 |
| air-sensors | temperature | TLM0200 | 1627049700000000000 | 74.17 |
---
### Query a raw CSV string
1. Import the [`csv` package](/flux/v0.x/stdlib/csv/).
2. Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) and provide the following parameters:
- **csv**: CSV string to query
- **mode**: raw
#### Query
```js
import "csv"
csvData = "
dataset,metric,sensorID,timestamp,value
air-sensors,humidity,TLM0100,1627049400000000000,34.79
air-sensors,humidity,TLM0100,1627049700000000000,34.65
air-sensors,humidity,TLM0200,1627049400000000000,35.64
air-sensors,humidity,TLM0200,1627049700000000000,35.67
air-sensors,temperature,TLM0100,1627049400000000000,71.84
air-sensors,temperature,TLM0100,1627049700000000000,71.87
air-sensors,temperature,TLM0200,1627049400000000000,74.10
air-sensors,temperature,TLM0200,1627049700000000000,74.17
"
csv.from(csv: csvData, mode: "raw")
```
#### Results
{{% note %}}
When using the **raw** CSV parsing mode, all columns values are strings.
{{% /note %}}
| dataset | metric | sensorID | timestamp | value |
| :---------- | :---------- | :------- | :------------------ | ----: |
| air-sensors | humidity | TLM0100 | 1627049400000000000 | 34.79 |
| air-sensors | humidity | TLM0100 | 1627049700000000000 | 34.65 |
| air-sensors | humidity | TLM0200 | 1627049400000000000 | 35.64 |
| air-sensors | humidity | TLM0200 | 1627049700000000000 | 35.67 |
| air-sensors | temperature | TLM0100 | 1627049400000000000 | 71.84 |
| air-sensors | temperature | TLM0100 | 1627049700000000000 | 71.87 |
| air-sensors | temperature | TLM0200 | 1627049400000000000 | 74.10 |
| air-sensors | temperature | TLM0200 | 1627049700000000000 | 74.17 |
---
### Query CSV data from a file
1. Import the [`csv` package](/flux/v0.x/stdlib/csv/).
2. Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) and the `file` parameter to
query CSV data from a file.
{{% note %}}
#### Flux must have access to the file system
To query CSV data from a file, Flux must have access to the filesystem.
If Flux does not have access to the file system, the query will return an error
similar to:
```
failed to read file: filesystem service is uninitialized
```
If using InfluxDB Cloud or InfluxDB OSS, the Flux process **does not** have
access to the filesystem.
{{% /note %}}
#### Query
```js
import "csv"
csv.from(file: "/path/to/example.csv")
```
#### /path/to/example.csv
```csv
#group,false,false,true,true,true,false,false
#datatype,string,long,string,string,string,long,double
#default,_result,,,,,,
,result,table,dataset,metric,sensorID,timestamp,value
,,0,air-sensors,humidity,TLM0100,1627049400000000000,34.79
,,0,air-sensors,humidity,TLM0100,1627049700000000000,34.65
,,1,air-sensors,humidity,TLM0200,1627049400000000000,35.64
,,1,air-sensors,humidity,TLM0200,1627049700000000000,35.67
,,2,air-sensors,temperature,TLM0100,1627049400000000000,71.84
,,2,air-sensors,temperature,TLM0100,1627049700000000000,71.87
,,3,air-sensors,temperature,TLM0200,1627049400000000000,74.10
,,3,air-sensors,temperature,TLM0200,1627049700000000000,74.17
```
#### Results
| dataset | metric | sensorID | timestamp | value |
| :---------- | :------- | :------- | :------------------ | ----: |
| air-sensors | humidity | TLM0100 | 1627049400000000000 | 34.79 |
| air-sensors | humidity | TLM0100 | 1627049700000000000 | 34.65 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :------- | :------- | :------------------ | ----: |
| air-sensors | humidity | TLM0200 | 1627049400000000000 | 35.64 |
| air-sensors | humidity | TLM0200 | 1627049700000000000 | 35.67 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :---------- | :------- | :------------------ | ----: |
| air-sensors | temperature | TLM0100 | 1627049400000000000 | 71.84 |
| air-sensors | temperature | TLM0100 | 1627049700000000000 | 71.87 |
| dataset | metric | sensorID | timestamp | value |
| :---------- | :---------- | :------- | :------------------ | ----: |
| air-sensors | temperature | TLM0200 | 1627049400000000000 | 74.10 |
| air-sensors | temperature | TLM0200 | 1627049700000000000 | 74.17 |
---
### Query CSV data from a URL
1. Import the [`experimental/csv` package](/flux/v0.x/stdlib/experimental/csv/).
2. Use the [experimental `csv.from()` function](/flux/v0.x/stdlib/experimental/csv/from/)
and `url` parameter to specify the URL to query.
{{% note %}}
The **experimental `csv.from()`** function does not support multiple parsing modes
and only works with [annotated CSV](/influxdb/cloud/reference/syntax/annotated-csv/).
{{% /note %}}
```js
import "experimental/csv"
csv.from(url: "https://example.com/example.csv")
```
**To use the parsing modes available in `csv.from()`:**
1. Import the [`csv`](/flux/v0.x/stdlib/csv/) and [`experimental/http`](/flux/v0.x/stdlib/experimental/http/) packages.
2. Use [`http.get()`](/flux/v0.x/stdlib/experimental/http/) to fetch the CSV data.
3. Use [`string()`](/flux/v0.x/stdlib/universe/string/) to convert the response body to a string.
4. Use [`csv.from()`](/flux/v0.x/stdlib/csv/from/) to parse the CSV data and return results.
```js
import "csv"
import "experimental/http"
url = "https://example.com/example.csv"
csvData = string(v: http.get(url: url).body)
csv.from(csv: csvData, mode: "raw")
```

View File

@ -0,0 +1,125 @@
---
title: Query InfluxDB
list_title: InfluxDB
description: >
Use [`from()`](/flux/v0.x/stdlib/influxdata/influxdb/from/) and [`range`](/flux/v0.x/stdlib/universe/range/)
to query data from InfluxDB using Flux.
menu:
flux_0_x:
name: InfluxDB
parent: Query data sources
weight: 101
related:
- /influxdb/cloud/query-data/optimize-queries/, Optimize Flux queries for InfluxDB
list_code_example: |
```js
from(bucket: "example-bucket")
|> range(start: -1h)
```
---
To query data from InfluxDB using Flux, use [`from()`](/flux/v0.x/stdlib/influxdata/influxdb/from/)
and [`range`](/flux/v0.x/stdlib/universe/range/).
Provide the following parameters to each function:
- **from()**:
- **bucket** or **bucketID**: _InfluxDB bucket name_ or _bucket ID_ to query.
- **range()**:
- **start**: Earliest time to return results from.
{{% note %}}
InfluxDB requires queries to be time-bound, so `from()` must always be followed by
[`range()`](/flux/v0.x/stdlib/universe/range/).
{{% /note %}}
```js
from(bucket: "example-bucket")
|> range(start: -1h)
```
## Query InfluxDB Cloud or 2.x remotely
To query InfluxDB Cloud or 2.x remotely, provide the following parameters
in addition to **bucket** or **bucketID**.
- **host**: [InfluxDB Cloud region URL](/influxdb/cloud/reference/urls/) or
[InfluxDB URL](/{{< latest "influxdb" >}}/reference/urls/)
- **org** or **orgID**: InfluxDB organization name or ID
- **token**: InfluxDB [API token](/influxdb/cloud/security/tokens/)
```js
from(
bucket: "example-bucket",
host: "http://localhost:8086",
org: "example-org",
token: "mYSup3r5Ecr3T70keN"
)
```
## Query InfluxDB 1.x
To query InfluxDB 1.x, use the `database-name/retention-policy-name` naming
convention for your bucket name.
For example, to query data from the `autogen` retention policy in the `telegraf` database:
```js
from(bucket: "telegraf/autogen")
|> range(start: -30m)
```
To query the [default retention policy](/{{< latest "influxdb" "v1" >}}/query_language/manage-database/#create-a-retention-policy) in a database, use the same bucket naming
convention, but do not provide a retention policy:
```js
from(bucket: "telegraf/")
|> range(start: -30m)
```
## Results structure
`from()` and `range()` return a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
grouped by [series](/influxdb/cloud/reference/glossary/#series)
(measurement, tag set, and field).
Each table includes the following columns:
- **_start**: Query range start time (defined by `range()`)
- **_stop**: Query range stop time (defined by `range()`)
- **_time**: Data timestamp
- **_measurement**: Measurement name
- **_field**: Field key
- **_value**: Field value
- **Tag columns**: A column for each tag where the column label is the tag key
and the column value is the tag value
{{% note %}}
#### Columns with the underscore prefix
Columns with the underscore (`_`) prefix are considered "system" columns.
Some Flux functions require these columns.
{{% /note %}}
### Example InfluxDB query results
{{% caption %}}
Hover over highlighted text to view description.
{{% /caption %}}
| _start | _stop | _time | _measurement | {{< tooltip "Tag key" "host" >}} | _field | _value |
| :-------------------------------------------------------- | :------------------------------------------------------- | :------------------------------------------------- | :--------------------------------------- | :---------------------------------- | :-------------------------------- | ----------------------------------: |
| 2021-01-01T00:00:00Z | 2021-01-02T00:00:00Z | 2021-01-01T00:00:00Z | foo | host1 | bar | 1.2 |
| {{< tooltip "Time range start" "2021-01-01T00:00:00Z" >}} | {{< tooltip "Time range stop" "2021-01-02T00:00:00Z" >}} | {{< tooltip "Timestamp" "2021-01-01T01:00:00Z" >}} | {{< tooltip "Measurement name" "foo" >}} | {{< tooltip "Tag value" "host1" >}} | {{< tooltip "Field key" "bar" >}} | {{< tooltip "Field value" "1.6" >}} |
| 2021-01-01T00:00:00Z | 2021-01-02T00:00:00Z | 2021-01-01T02:00:00Z | foo | host1 | bar | 2.1 |
| _start | _stop | _time | _measurement | host | _field | _value |
| :------------------- | :------------------- | :------------------- | :----------- | :---- | :----- | -----: |
| 2021-01-01T00:00:00Z | 2021-01-02T00:00:00Z | 2021-01-01T00:00:00Z | foo | host2 | bar | 1.2 |
| 2021-01-01T00:00:00Z | 2021-01-02T00:00:00Z | 2021-01-01T01:00:00Z | foo | host2 | bar | 1.7 |
| 2021-01-01T00:00:00Z | 2021-01-02T00:00:00Z | 2021-01-01T02:00:00Z | foo | host2 | bar | 2.1 |
{{% note %}}
#### Structure results like InfluxQL
[InfluxQL](/{{< latest "influxdb" "v1" >}}/query_language/) returns each field as
a column where the column label is the field key and the column value is the field value.
To structure results similarly with Flux, use [`pivot()`](/flux/v0.x/stdlib/universe/pivot/)
or [`schema.fieldsAsCols()`](/flux/v0.x/stdlib/influxdata/influxdb/schema/fieldsascols/)
to pivot fields into columns.
{{% /note %}}

View File

@ -0,0 +1,119 @@
---
title: Scrape Prometheus metrics
list_title: Prometheus
description: >
Use [`prometheus.scrape`](/flux/v0.x/stdlib/experimental/prometheus/scrape) to
scrape Prometheus-formatted metrics from an HTTP-accessible endpoint using Flux.
menu:
flux_0_x:
name: Prometheus
parent: Query data sources
weight: 104
list_code_example: |
```js
import "experimental/prometheus"
prometheus.scrape(url: "http://example.com/metrics")
```
draft: true
---
To scrape Prometheus-formatted metrics from an HTTP-accessible endpoint using Flux:
1. Import the [`experimental/prometheus` package](/flux/v0.x/stdlib/experimental/prometheus/).
2. Use [`prometheus.scrape`](/flux/v0.x/stdlib/experimental/prometheus/scrape).
Use the **url** parameter to provide the URL to scrape metrics from.
{{< keep-url >}}
```js
import "experimental/prometheus"
prometheus.scrape(url: "http://localhost:8086/metrics")
```
## Results structure
`prometheus.scrape()` returns a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
with the following columns:
- **_time**: Data timestamp
- **_measurement**: `prometheus`
- **_field**: [Prometheus metric name](https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels)
- **_value**: [Prometheus metric value](https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels)
- **url**: URL metrics were scraped from
- **Label columns**: A column for each [Prometheus label](https://prometheus.io/docs/concepts/data_model/#metric-names-and-labels).
The column label is the label name and the column value is the label value.
Tables are grouped by **_measurement**, **_field**, and **Label columns**.
{{% note %}}
#### Columns with the underscore prefix
Columns with the underscore (`_`) prefix are considered "system" columns.
Some Flux functions require these columns to function properly.
{{% /note %}}
### Example Prometheus query results
The following are example Prometheus metrics scraped from the InfluxDB OSS 2.x `/metrics` endpoint:
```sh
# HELP go_goroutines Number of goroutines that currently exist.
# TYPE go_goroutines gauge
go_goroutines 1263
# HELP go_info Information about the Go environment.
# TYPE go_info gauge
go_info{version="go1.16.3"} 1
# HELP go_memstats_alloc_bytes Number of bytes allocated and still in use.
# TYPE go_memstats_alloc_bytes gauge
go_memstats_alloc_bytes 2.6598832e+07
# HELP go_memstats_alloc_bytes_total Total number of bytes allocated, even if freed.
# TYPE go_memstats_alloc_bytes_total counter
go_memstats_alloc_bytes_total 1.42276424e+09
# HELP go_memstats_buck_hash_sys_bytes Number of bytes used by the profiling bucket hash table.
# TYPE go_memstats_buck_hash_sys_bytes gauge
go_memstats_buck_hash_sys_bytes 5.259247e+06
```
When scraped by Flux, these metrics return the following stream of tables:
| _time | _measurement | _field | _value | url |
| :------------------- | :----------- | :------------ | -----: | :---------------------------- |
| 2021-01-01T00:00:00Z | prometheus | go_goroutines | 1263 | http://localhost:8086/metrics |
| _time | _measurement | _field | _value | url | version |
| :------------------- | :----------- | :------ | -----: | :---------------------------- | -------- |
| 2021-01-01T00:00:00Z | prometheus | go_info | 1 | http://localhost:8086/metrics | go1.16.3 |
| _time | _measurement | _field | _value | url |
| :------------------- | :----------- | :---------------------- | -------: | :---------------------------- |
| 2021-01-01T00:00:00Z | prometheus | go_memstats_alloc_bytes | 26598832 | http://localhost:8086/metrics |
| _time | _measurement | _field | _value | url |
| :------------------- | :----------- | :---------------------------- | ---------: | :---------------------------- |
| 2021-01-01T00:00:00Z | prometheus | go_memstats_alloc_bytes_total | 1422764240 | http://localhost:8086/metrics |
| _time | _measurement | _field | _value | url |
| :------------------- | :----------- | :------------------------------ | ------: | :---------------------------- |
| 2021-01-01T00:00:00Z | prometheus | go_memstats_buck_hash_sys_bytes | 5259247 | http://localhost:8086/metrics |
{{% note %}}
#### Write Prometheus metrics to InfluxDB
To write scraped Prometheus metrics to InfluxDB:
1. Use `prometheus.scrape()` to scrape Prometheus metrics.
2. Use [`to()`](/flux/v0.x/stdlib/influxdata/influxdb/to/) to write the scraped
metrics to InfluxDB.
```js
import "experimental/prometheus"
prometheus.scrape(url: "http://example.com/metrics")
|> to(
bucket: "example-bucket",
host: "http://localhost:8086",
org: "example-org",
token: "mYsuP3R5eCR37t0K3n"
)
```
To scrape Prometheus metrics and write them to InfluxDB at regular intervals,
use the example above to [create an InfluxDB task](/influxdb/cloud/process-data/get-started/).
{{% /note %}}

View File

@ -0,0 +1,121 @@
---
title: Query SQL databases
list_title: SQL databases
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) to query SQL databases with Flux.
menu:
flux_0_x:
name: SQL databases
parent: Query data sources
weight: 102
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://user:password@localhost",
query:"SELECT * FROM TestTable"
)
```
---
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) to query SQL databases with Flux.
- [Databases](#databases)
- [Drivers](#drivers)
- [Data source names](#data-source-names)
- [Store sensitive credentials as secrets](#store-sensitive-credentials-as-secrets)
- [Results structure](#results-structure)
- [Column data types](#column-data-types)
## Databases
`sql.from()` supports the following SQL databases:
{{< children type="list" >}}
## Drivers
`sql.from()` uses [Go SQL drivers](https://github.com/golang/go/wiki/SQLDrivers)
in the [Go sql package](https://pkg.go.dev/database/sql) to connect to SQL databases.
The following drivers are available:
- `awsathena`
- `bigquery`
- `hdb`
- `mysql`
- `postgres`
- `snowflake`
- `sqlite3`
- `sqlserver`, `mssql`
## Data source names
Each [SQL driver](#drivers) supports unique data source name (DSN) syntaxes
(also known as **connection strings**).
_See the [database guides](#databases) for information about DSNs for each driver._
#### Store sensitive credentials as secrets
If using **InfluxDB Cloud** or **InfluxDB OSS 2.x**, we recommend storing DSN
credentials as [InfluxDB secrets](/influxdb/cloud/security/secrets/).
Use [`secrets.get()`](/flux/v0.x/stdlib/influxdata/influxdb/secrets/get/) to
retrieve a secret from the InfluxDB secrets API.
```js
import "sql"
import "influxdata/influxdb/secrets"
username = secrets.get(key: "POSTGRES_USER")
password = secrets.get(key: "POSTGRES_PASS")
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://${username}:${password}@localhost:5432",
query: "SELECT * FROM example_table"
)
```
## Results structure
`sql.from()` returns a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
with no grouping (all rows in a single table).
_For more information about table grouping, see
[Flux data model - Restructure tables](/flux/v0.x/get-started/data-model/#restructure-tables)._
{{% note %}}
#### Column data types
Each `sql.from()` [driver](#drivers) converts column data types from the source
database into [Flux data types](/flux/v0.x/spec/types/#basic-types).
_See the [database guides](#databases) for information about data type conversions._
{{% /note %}}
Given the following **example_table** in a MySQL database:
##### example_table
| ID | Name | Address | Country |
| :-: | :--------------------------------- | :---------------------------- | :------ |
| 1 | Alfreds Futterkiste | Obere Str. 57 | Germany |
| 2 | Ana Trujillo Emparedados y helados | Avda. de la Constitución 2222 | Mexico |
| 3 | Antonio Moreno Taquería | Mataderos 2312 | Mexico |
| 4 | Around the Horn | 120 Hanover Sq. | UK |
| 5 | Berglunds snabbköp | Berguvsvägen 8 | Sweden |
##### Flux query
```js
import "sql"
sql.from(
driver: "mysql",
dataSourceName: "username:passwOrd@tcp(localhost:3306)/db",
query: "SELECT ID, Name FROM example_table"
)
```
##### Output
| ID | Name |
| :-: | :--------------------------------- |
| 1 | Alfreds Futterkiste |
| 2 | Ana Trujillo Emparedados y helados |
| 3 | Antonio Moreno Taquería |
| 4 | Around the Horn |
| 5 | Berglunds snabbköp |

View File

@ -0,0 +1,63 @@
---
title: Query Amazon RDS
list_title: Amazon RDS
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) to query a relational database
hosted on Amazon RDS.
menu:
flux_0_x:
name: Amazon RDS
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://my-instance.123456789012.us-east-1.rds.amazonaws.com:5432",
query: "SELECT * FROM example_table"
)
```
---
To query a relational database hosted on [Amazon Relational Database Service (RDS)](https://aws.amazon.com/rds/)
with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/)
2. Use the [`sql.from()` function](/flux/v0.x/stdlib/sql/from/) and provide the
following parameters:
- **driverName**: _Determined by your [Amazon RDS database engine](#supported-database-engines)_
- **dataSourceName**: _Determined by your [Amazon RDS database engine](#supported-database-engines)_
- **query**: SQL query to execute
##### Query Amazon RDS PostgreSQL database
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://my-instance.123456789012.us-east-1.rds.amazonaws.com:5432",
query: "SELECT * FROM example_table"
)
```
## Supported database engines
Use the following guides to query supported Amazon RDS database engines:
- [Query MariaDB](/flux/v0.x/query-data/sql/mariadb/)
- [Query MySQL](/flux/v0.x/query-data/sql/mysql/)
- [Query PostgreSQL](/flux/v0.x/query-data/sql/postgresql/)
- [Query SQL Server](/flux/v0.x/query-data/sql/sql-server/)
## Amazon RDS connection credentials
Amazon RDS provides connection credentials required to connect to your database instance.
The following links provide more information for each database engine:
- [Connect to MariaDB](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMariaDBInstance.html)
- [Connect to MySQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToInstance.html)
- [Connect to PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToPostgreSQLInstance.html)
- [Connect to SQL Server](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ConnectToMicrosoftSQLServerInstance.html)

View File

@ -0,0 +1,79 @@
---
title: Query Amazon Athena
list_title: Amazon Athena
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `awsathena` driver to query Athena.
menu:
flux_0_x:
name: Athena
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "awsathena",
dataSourceName: "s3://myorgqueryresults/?accessID=12ab34cd56ef&region=region-name&secretAccessKey=y0urSup3rs3crEtT0k3n",
query: "GO SELECT * FROM Example.Table"
)
```
---
To query [Amazon Athena](https://aws.amazon.com/athena) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: awsathena
- **dataSourceName**: _See [data source name](#amazon-athena-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "awsathena",
dataSourceName: "s3://myorgqueryresults/?accessID=12ab34cd56ef&region=region-name&secretAccessKey=y0urSup3rs3crEtT0k3n",
query: "GO SELECT * FROM Example.Table"
)
```
---
## Amazon Athena data source name
The `awsathena` driver uses the following data source name (DSN) syntaxes (also known as a **connection string**):
```
s3://myorgqueryresults/?accessID=AKIAJLO3F...&region=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F...
s3://myorgqueryresults/?accessID=AKIAJLO3F...&db=dbname&missingAsDefault=false&missingAsEmptyString=false&region=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F...&WGRemoteCreation=false
```
Use the following query parameters in your Athena S3 DSN:
{{< req type="key" >}}
- {{< req "\*" >}} **region** - AWS region
- {{< req "\*" >}} **accessID** - AWS IAM access ID
- {{< req "\*" >}} **secretAccessKey** - AWS IAM secret key
- **db** - database name
- **WGRemoteCreation** - controls workgroup and tag creation
- **missingAsDefault** - replace missing data with default values
- **missingAsEmptyString** - replace missing data with empty strings
## Athena to Flux data type conversion
`sql.from()` converts Athena data types to Flux data types.
| Athena data type | Flux data type |
| :-------------------------------------- | :------------------------------------------ |
| tinyint, smallint, int, integer, bigint | [int](/flux/v0.x/data-types/basic/int/) |
| float, double, real | [float](/flux/v0.x/data-types/basic/float/) |
| timestamp with time zone | [time](/flux/v0.x/data-types/basic/time/) |
| boolean | [bool](/flux/v0.x/data-types/basic/bool/) |
{{% caption %}}
All other Athena data types (including **timestamp**, **date** and **time**)
are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,91 @@
---
title: Query Google BigQuery
list_title: BigQuery
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `bigquery` driver to query Google BigQuery.
menu:
flux_0_x:
name: BigQuery
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "bigquery",
dataSourceName: "bigquery://projectid/?apiKey=mySuP3r5ecR3tAP1K3y",
query: "SELECT * FROM exampleTable"
)
```
---
To query [Google BigQuery](https://cloud.google.com/bigquery) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: bigquery
- **dataSourceName**: _See [data source name](#bigquery-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "bigquery",
dataSourceName: "bigquery://projectid/?apiKey=mySuP3r5ecR3tAP1K3y",
query: "SELECT * FROM exampleTable"
)
```
---
## BigQuery data source name
The `bigquery` driver uses the following DSN syntaxes (also known as a **connection string**):
```
bigquery://projectid/?param1=value&param2=value
bigquery://projectid/location?param1=value&param2=value
```
### Common BigQuery URL parameters
- **dataset** - BigQuery dataset ID. When set, you can use unqualified table names in queries.
### BigQuery authentication parameters
The Flux BigQuery implementation uses the [Google Cloud Go SDK](https://cloud.google.com/go/docs/reference/cloud.google.com/go/latest).
Provide your authentication credentials using one of the following methods:
- Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to identify the
location of your credential JSON file.
- Provide your BigQuery API key using the **apiKey** URL parameter in your BigQuery DSN.
###### Example apiKey URL parameter
```
bigquery://projectid/?apiKey=AIzaSyB6XK8IO5AzKZXoioQOVNTFYzbDBjY5hy4
```
- Provide your base-64 encoded service account, refresh token, or JSON credentials
using the **credentials** URL parameter in your BigQuery DSN.
###### Example credentials URL parameter
```
bigquery://projectid/?credentials=eyJ0eXBlIjoiYXV0...
```
## Data type conversion
`sql.from()` converts BigQuery data types to Flux data types.
| BigQuery data type | Flux data type |
| :----------------- | :------------------------------------------ |
| INTEGER | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT, NUMERIC | [float](/flux/v0.x/data-types/basic/float/) |
| TIMESTAMP | [time](/flux/v0.x/data-types/basic/time/) |
| BOOLEAN | [bool](/flux/v0.x/data-types/basic/bool/) |
{{% caption %}}
All other BigQuery data types (including **DATE**, **TIME** and **DATETIME**)
are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,72 @@
---
title: Query CockroachDB
list_title: CockroachDB
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `postgres` driver to query CockroachDB.
menu:
flux_0_x:
name: CockroachDB
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://username:password@localhost:26257/cluster_name.defaultdb?sslmode=verify-full&sslrootcert=certs_dir/cc-ca.crt",
query: "SELECT * FROM example_table"
)
```
---
To query [CockroachDB](https://www.cockroachlabs.com/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: postgres
- **dataSourceName**: _See [data source name](#cockroachdb-data-source-name)_
- **query**: PSQL query to execute
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://username:password@localhost:26257/cluster_name.defaultdb?sslmode=verify-full&sslrootcert=certs_dir/cc-ca.crt",
query: "SELECT * FROM example_table"
)
```
---
## CockroachDB data source name
The `postgres` driver uses the following DSN syntax (also known as a **connection string**)
to connect to CockroachDB :
```
postgres://username:password@localhost:26257/cluster_name.defaultdb?sslmode=verify-full&sslrootcert=certs_dir/cc-ca.crt
```
{{% note %}}
The `postgres` driver use the [Go `pq` implementation](https://www.cockroachlabs.com/docs/stable/build-a-go-app-with-cockroachdb-pq)
to interact with CockroachDB.
{{% /note %}}
## CockroachDB to Flux data type conversion
`sql.from()` converts PostgreSQL and CockroachDB data types to Flux data types.
| CockroachDB data type | Flux data type |
| :-------------------------------------------------------------------------- | :-------------------------------------------- |
| INT, BIGINT, SMALLINT, TINYINT, INT2, INT4, INT8, SERIAL2, SERIAL4, SERIAL8 | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT4, FLOAT8 | [float](/flux/v0.x/data-types/basic/float/) |
| DATE, TIME, TIMESTAMP | [time](/flux/v0.x/data-types/basic/time/) |
| BOOL | [bool](/flux/v0.x/data-types/basic/bool/) |
| TEXT | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other CockroachDB data types are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,65 @@
---
title: Query MariaDB
list_title: MariaDB
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `mysql` driver to query MariaDB.
menu:
flux_0_x:
name: MariaDB
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
To query [MariaDB](https://mariadb.org/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: mysql
- **dataSourceName**: _See [data source name](#mariadb-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
## MariaDB data source name
The `mysql` driver uses the following data source name (DSN) syntax (also known as a **connection string**):
```
username:password@tcp(localhost:3306)/dbname?param=value
```
## MariaDB to Flux data type conversion
`sql.from()` converts MariaDB data types to Flux data types.
| MariaDB data type | Flux data type |
| :----------------------------- | :-------------------------------------------- |
| INT, BIGINT, SMALLINT, TINYINT | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT, DOUBLE | [float](/flux/v0.x/data-types/basic/float/) |
| DATETIME | [time](/flux/v0.x/data-types/basic/time/) |
| STRING | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other MariaDB data types are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,65 @@
---
title: Query MySQL
list_title: MySQL
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `mysql` driver to query MySQL.
menu:
flux_0_x:
name: MySQL
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
To query [MySQL](https://www.mysql.com/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: mysql
- **dataSourceName**: _See [data source name](#mysql-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
## MySQL data source name
The `mysql` driver uses the following data source name (DSN) syntax (also known as a **connection string**):
```
username:password@tcp(localhost:3306)/dbname?param=value
```
## MySQL to Flux data type conversion
`sql.from()` converts MySQL data types to Flux data types.
| MySQL data type | Flux data type |
| :----------------------------- | :-------------------------------------------- |
| INT, BIGINT, SMALLINT, TINYINT | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT, DOUBLE | [float](/flux/v0.x/data-types/basic/float/) |
| DATETIME | [time](/flux/v0.x/data-types/basic/time/) |
| STRING | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other MySQL data types are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,65 @@
---
title: Query Percona
list_title: Percona
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `mysql` driver to query Percona.
menu:
flux_0_x:
name: Percona
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
To query [Percona](https://www.percona.com/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: mysql
- **dataSourceName**: _See [data source name](#percona-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "mysql",
dataSourceName: "user:password@tcp(localhost:3306)/db",
query: "SELECT * FROM example_table"
)
```
---
## Percona data source name
The `mysql` driver uses the following data source name (DSN) syntax (also known as a **connection string**):
```
username:password@tcp(localhost:3306)/dbname?param=value
```
## Percona to Flux data type conversion
`sql.from()` converts Percona data types to Flux data types.
| Percona data type | Flux data type |
| :----------------------------- | :-------------------------------------------- |
| INT, BIGINT, SMALLINT, TINYINT | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT, DOUBLE | [float](/flux/v0.x/data-types/basic/float/) |
| DATETIME | [time](/flux/v0.x/data-types/basic/time/) |
| STRING | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other Percona data types are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,72 @@
---
title: Query PostgreSQL
list_title: PostgreSQL
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `postgres` driver to query PostgreSQL.
menu:
flux_0_x:
name: PostgreSQL
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://username:password@localhost:5432",
query: "SELECT * FROM example_table"
)
```
---
To query [PostgreSQL](https://www.postgresql.org/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: postgres
- **dataSourceName**: _See [data source name](#postgresql-data-source-name)_
- **query**: PSQL query to execute
```js
import "sql"
sql.from(
driverName: "postgres",
dataSourceName: "postgresql://username:password@localhost:5432",
query: "SELECT * FROM example_table"
)
```
---
## PostgreSQL data source name
The `postgres` driver uses the following DSN syntax (also known as a **connection string**):
```
postgres://username:password@localhost:5432/dbname?param=value
```
## PostgreSQL to Flux data type conversion
`sql.from()` converts PostgreSQL data types to Flux data types.
| PostgreSQL data type | Flux data type |
| :-------------------------------------------------------------------------- | :-------------------------------------------- |
| INT, BIGINT, SMALLINT, TINYINT, INT2, INT4, INT8, SERIAL2, SERIAL4, SERIAL8 | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT4, FLOAT8 | [float](/flux/v0.x/data-types/basic/float/) |
| DATE, TIME, TIMESTAMP | [time](/flux/v0.x/data-types/basic/time/) |
| BOOL | [bool](/flux/v0.x/data-types/basic/bool/) |
| TEXT | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other PostgreSQL data types are converted to strings.
{{% /caption %}}
## Results structure
`sql.from()` returns a [stream of tables](/flux/v0.x/get-started/data-model/#stream-of-tables)
with no grouping (all rows in a single table).
For more information about table grouping, see
[Flux data model - Restructure tables](/flux/v0.x/get-started/data-model/#restructure-tables).

View File

@ -0,0 +1,71 @@
---
title: Query SAP HANA
list_title: SAP HANA
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `hdb` driver to query SAP HANA.
menu:
flux_0_x:
name: SAP HANA
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "hdb",
dataSourceName: "hdb://username:password@myserver:30015",
query: "SELECT * FROM SCHEMA.TABLE"
)
```
---
To query [SAP HANA](https://www.sap.com/products/hana.html) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: hdb
- **dataSourceName**: _See [data source name](#sap-hana-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "hdb",
dataSourceName: "hdb://username:password@myserver:30015",
query: "SELECT * FROM SCHEMA.TABLE"
)
```
---
## SAP HANA data source name
The `hdb` driver uses the following DSN syntaxes (also known as a **connection string**):
```
hdb://<user>:<password>@<host>:<port>?<connection-property>=<value>&<connection-property>=<value>&...
hdb://<user>:<password>@<host>:<port>?DATABASENAME=<tenant-db-name>
hdb://?KEY=<keyname>
```
## SAP HANA to Flux data type conversion
`sql.from()` converts SAP HANA data types to Flux data types.
| SAP HANA data type | Flux data type |
| :---------------------------------------------- | :------------------------------------------ |
| TINYINT, SMALLINT, INTEGER, BIGINT | [int](/flux/v0.x/data-types/basic/int/) |
| REAL, DOUBLE, DECIMAL | [float](/flux/v0.x/data-types/basic/float/) |
| {{< req text="\*" color="magenta" >}} TIMESTAMP | [time](/flux/v0.x/data-types/basic/time/) |
{{% caption %}}
All other SAP HANA data types are converted to strings.
{{% /caption %}}
{{< req text="\*" color="magenta" >}} The SAP HANA **TIMESTAMP** data type does
not store time zone information and
[SAP strongly discourages storing data in the local time zone](https://blogs.sap.com/2018/03/28/trouble-with-time/).
For more information, see [Timestamps in SAP HANA](https://help.sap.com/viewer/f1b440ded6144a54ada97ff95dac7adf/2.4/en-US/a394f75dcbe64b42b7a887231af8f15f.html).

View File

@ -0,0 +1,68 @@
---
title: Query Snowflake
list_title: Snowflake
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `snowflake` driver to query Snowflake.
menu:
flux_0_x:
name: Snowflake
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "snowflake",
dataSourceName: "user:password@account/db/exampleschema?warehouse=wh",
query: "SELECT * FROM example_table"
)
```
---
To query [Snowflake](https://www.snowflake.com/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: snowflake
- **dataSourceName**: _See [data source name](#snowflake-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "snowflake",
dataSourceName: "user:password@account/db/exampleschema?warehouse=wh",
query: "SELECT * FROM example_table"
)
```
---
## Snowflake data source name
The `snowflake` driver uses the following DSN syntaxes (also known as a **connection string**):
```
username[:password]@accountname/dbname/schemaname?param1=value1&paramN=valueN
username[:password]@accountname/dbname?param1=value1&paramN=valueN
username[:password]@hostname:port/dbname/schemaname?account=<your_account>&param1=value1&paramN=valueN
```
## Snowflake to Flux data type conversion
`sql.from()` converts Snowflake data types to Flux data types.
| Snowflake data type | Flux data type |
| :-------------------------- | :----------------------------------------------------------------------------------------------------------------- |
| FIXED, NUMBER | [int](/flux/v0.x/data-types/basic/int/) or [float](/flux/v0.x/data-types/basic/float/) (depending on decimal size) |
| REAL, FLOAT | [float](/flux/v0.x/data-types/basic/float/) |
| TIMESTAMP_TZ, TIMESTAMP_LTZ | [time](/flux/v0.x/data-types/basic/time/) |
| BOOLEAN | [bool](/flux/v0.x/data-types/basic/bool/) |
{{% caption %}}
All other Snowflake data types (including **TIMESTAMP_NTZ**, **DATE** and **TIME**)
are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,120 @@
---
title: Query SQL Server
list_title: SQL Server
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `sqlserver` or `mssql`
driver to query SQL Server.
menu:
flux_0_x:
name: SQL Server
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "sqlserver",
dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
query: "GO SELECT * FROM Example.Table"
)
```
---
To query [Microsoft SQL Server](https://www.microsoft.com/sql-server/) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: sqlserver _or_ mssql
- **dataSourceName**: _See [data source name](#sql-server-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "sqlserver",
dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
query: "GO SELECT * FROM Example.Table"
)
```
---
- [SQL Server data source name](#sql-server-data-source-name)
- [SQL Server ADO authentication](#sql-server-ado-authentication)
- [SQL Server to Flux data type conversion](#sql-server-to-flux-data-type-conversion)
## SQL Server data source name
The `sqlserver` and `mssql` drivers use the following DSN syntaxes (also known as a **connection string**):
```
sqlserver://username:password@localhost:1433?database=examplebdb
server=localhost;user id=username;database=examplebdb;
server=localhost;user id=username;database=examplebdb;azure auth=ENV
server=localhost;user id=username;database=examplebdbr;azure tenant id=77e7d537;azure client id=58879ce8;azure client secret=0143356789
```
## SQL Server ADO authentication
Use one of the following methods to provide SQL Server authentication credentials as
[ActiveX Data Objects (ADO)](https://docs.microsoft.com/en-us/sql/ado/guide/ado-introduction?view=sql-server-ver15)
DSN parameters:
- [Retrieve authentication credentials from environment variables](#retrieve-authentication-credentials-from-environment-variables)
- [Retrieve authentication credentials from a file](#retrieve-authentication-credentials-from-a-file)
- [Specify authentication credentials in the DSN](#specify-authentication-credentials-in-the-dsn)
- [Use a Managed identity in an Azure VM](#use-a-managed-identity-in-an-azure-vm)
### Retrieve authentication credentials from environment variables
```
azure auth=ENV
```
### Retrieve authentication credentials from a file
{{% warn %}}
**{{< cloud-name "short" >}}** and **InfluxDB OSS** _**do not**_ have access to
the underlying file system and do not support reading credentials from a file.
To retrieve SQL Server credentials from a file, execute the query in the
[Flux REPL](/{{< latest "influxdb" >}}/tools/repl/) on your local machine.
{{% /warn %}}
```powershell
azure auth=C:\secure\azure.auth
```
### Specify authentication credentials in the DSN
```powershell
# Example of providing tenant ID, client ID, and client secret token
azure tenant id=77...;azure client id=58...;azure client secret=0cf123..
# Example of providing tenant ID, client ID, certificate path and certificate password
azure tenant id=77...;azure client id=58...;azure certificate path=C:\secure\...;azure certificate password=xY...
# Example of providing tenant ID, client ID, and Azure username and password
azure tenant id=77...;azure client id=58...;azure username=some@myorg;azure password=a1...
```
### Use a managed identity in an Azure VM
_For information about managed identities, see [Microsoft managed identities](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview)._
```
azure auth=MSI
```
## SQL Server to Flux data type conversion
`sql.from()` converts SQL Server data types to Flux data types.
| SQL Server data type | Flux data type |
| :-------------------------------------- | :------------------------------------------ |
| INT, TINYINT, SMALLINT, BIGINT | [int](/flux/v0.x/data-types/basic/int/) |
| DECIMAL, REAL, FLOAT, MONEY, SMALLMONEY | [float](/flux/v0.x/data-types/basic/float/) |
| DATETIMEOFFSET | [time](/flux/v0.x/data-types/basic/time/) |
| BIT | [bool](/flux/v0.x/data-types/basic/bool/) |
{{% caption %}}
All other SQL Server data types (including other [date/time types](https://docs.microsoft.com/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-ver15#DateandTimeDataTypes))
are converted to strings.
{{% /caption %}}

View File

@ -0,0 +1,80 @@
---
title: Query SQLite
list_title: SQLite
description: >
Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) with the `sqlite3` driver to query SQLite.
menu:
flux_0_x:
name: SQLite
parent: SQL databases
weight: 101
related:
- /flux/v0.x/stdlib/sql/from/
list_code_example: |
```js
import "sql"
sql.from(
driverName: "sqlite3",
dataSourceName: "file:/path/to/example.db?cache=shared&mode=ro",
query: "SELECT * FROM example_table"
)
```
---
To query [SQLite](https://www.sqlite.org/index.html) with Flux:
1. Import the [`sql` package](/flux/v0.x/stdlib/sql/).
2. Use [`sql.from()`](/flux/v0.x/stdlib/sql/from/) and provide the following parameters:
- **driverName**: sqlite3
- **dataSourceName**: _See [data source name](#sqlite-data-source-name)_
- **query**: SQL query to execute
```js
import "sql"
sql.from(
driverName: "sqlite3",
dataSourceName: "file:/path/to/example.db?cache=shared&mode=ro",
query: "SELECT * FROM example_table"
)
```
{{% note %}}
#### Requires file system access
To query SQLite, Flux must have access to the filesystem.
If Flux does not have access to the file system, the query will return an error
similar to one of the following:
- `Error: unable to open database file`
- `failed to read file: filesystem service is uninitialized`
- `An internal error has occurred`
If using **InfluxDB Cloud** or **InfluxDB OSS**, the Flux process **does not**
have access to the filesystem.
{{% /note %}}
---
## SQLite data source name
The `sqlite3` driver uses the following DSN syntax (also known as a **connection string**):
```
file:/path/to/example.db?param=value
```
## SQLite to Flux data type conversion
`sql.from()` converts SQLite data types to Flux data types.
| SQLite data type | Flux data type |
| :-------------------------------------- | :-------------------------------------------- |
| INT, INTEGER, BIGINT, SMALLINT, TINYINT | [int](/flux/v0.x/data-types/basic/int/) |
| FLOAT, DOUBLE | [float](/flux/v0.x/data-types/basic/float/) |
| DATETIME, TIMESTAMP, DATE | [time](/flux/v0.x/data-types/basic/time/) |
| BOOL | [int](/flux/v0.x/data-types/basic/int/) |
| TEXT | [string](/flux/v0.x/data-types/basic/string/) |
{{% caption %}}
All other SQLite data types are converted to strings.
{{% /caption %}}

Some files were not shown because too many files have changed in this diff Show More