diff --git a/content/v2.0/query-data/flux/increase.md b/content/v2.0/query-data/flux/increase.md index 35971ebe1..b84cb1f54 100644 --- a/content/v2.0/query-data/flux/increase.md +++ b/content/v2.0/query-data/flux/increase.md @@ -3,7 +3,7 @@ title: Calculate the increase seotitle: Calculate the increase in Flux list_title: Increase description: > - Use the [`increase()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase/) + Use the [`increase()` function](/v2.0/reference/flux/stdlib/built-in/transformations/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. @@ -18,7 +18,7 @@ related: list_query_example: increase --- -Use the [`increase()` function](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase/) +Use the [`increase()` function](/v2.0/reference/flux/stdlib/built-in/transformations/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. diff --git a/content/v2.0/query-data/flux/rate.md b/content/v2.0/query-data/flux/rate.md index fb1a5825b..ec1535cd4 100644 --- a/content/v2.0/query-data/flux/rate.md +++ b/content/v2.0/query-data/flux/rate.md @@ -16,7 +16,7 @@ menu: name: Rate v2.0/tags: [query, rate] related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative/ + - /v2.0/reference/flux/stdlib/built-in/transformations/derivative/ - /v2.0/reference/flux/stdlib/experimental/aggregate/rate/ list_query_example: rate_of_change --- diff --git a/content/v2.0/query-data/flux/sql.md b/content/v2.0/query-data/flux/sql.md index 6baee5ac5..850d0a074 100644 --- a/content/v2.0/query-data/flux/sql.md +++ b/content/v2.0/query-data/flux/sql.md @@ -4,7 +4,8 @@ seotitle: Query SQL data sources with InfluxDB list_title: Query SQL data description: > The Flux `sql` package provides functions for working with SQL data sources. - Use `sql.from()` to query SQL databases like PostgreSQL, MySQL, Snowflake, and SQLite. + Use `sql.from()` to query SQL databases like PostgreSQL, MySQL, Snowflake, + SQLite, Microsoft SQL Server, and Amazon Athena. v2.0/tags: [query, flux, sql] menu: v2_0: @@ -30,8 +31,10 @@ list_code_example: | The [Flux](/v2.0/reference/flux) `sql` package provides functions for working with SQL data sources. [`sql.from()`](/v2.0/reference/flux/stdlib/sql/from/) lets you query SQL data sources like [PostgreSQL](https://www.postgresql.org/), [MySQL](https://www.mysql.com/), -[Snowflake](https://www.snowflake.com/), and [SQLite](https://www.sqlite.org/index.html), -and use the results with InfluxDB dashboards, tasks, and other operations. +[Snowflake](https://www.snowflake.com/), [SQLite](https://www.sqlite.org/index.html), +[Microsoft SQL Server](https://www.microsoft.com/en-us/sql-server/default.aspx), +and [Amazon Athena](https://aws.amazon.com/athena/) and use the results with +InfluxDB dashboards, tasks, and other operations. - [Query a SQL data source](#query-a-sql-data-source) - [Join SQL data with data in InfluxDB](#join-sql-data-with-data-in-influxdb) @@ -57,6 +60,7 @@ To query a SQL data source: [MySQL](#) [Snowflake](#) [SQLite](#) +[SQL Server](#) {{% /code-tabs %}} {{% code-tab-content %}} @@ -110,6 +114,21 @@ sql.from( ) ``` {{% /code-tab-content %}} + +{{% code-tab-content %}} +```js +import "sql" + +sql.from( + driverName: "sqlserver", + dataSourceName: "sqlserver://user:password@localhost:1234?database=examplebdb", + query: "GO SELECT * FROM Example.Table" +) +``` + +_For information about authenticating with SQL Server using ADO-style parameters, +see [SQL Server ADO authentication](/v2.0/reference/flux/stdlib/sql/from/#sql-server-ado-authentication)._ +{{% /code-tab-content %}} {{< /code-tabs-wrapper >}} _See the [`sql.from()` documentation](/v2.0/reference/flux/stdlib/sql/from/) for diff --git a/content/v2.0/reference/flux/stdlib/built-in/misc/now.md b/content/v2.0/reference/flux/stdlib/built-in/misc/now.md index bcc5048c8..3b38aaf35 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/misc/now.md +++ b/content/v2.0/reference/flux/stdlib/built-in/misc/now.md @@ -12,7 +12,7 @@ related: - /v2.0/reference/flux/stdlib/system/time/ --- -The `now()` function returns the current time (UTC). +The `now()` function returns the current time (UTC) or the time defined in the `now` option. _**Function type:** Date/Time_ _**Output data type:** Time_ @@ -22,11 +22,21 @@ now() ``` ## Examples + +##### Use the current UTC time as a query boundary ```js data |> range(start: -10h, stop: now()) ``` +##### Return the now option time +```js +option now = () => 2020-01-01T00:00:00Z + +now() +// Returns 2020-01-01T00:00:00.000000000Z +``` + {{% note %}} #### now() vs system.time() `now()` returns the current UTC time. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/_index.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/_index.md index 30f6441f4..0a9435059 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/_index.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/_index.md @@ -1,7 +1,9 @@ --- -title: Flux built-in aggregate functions -list_title: Built-in aggregate functions -description: Flux's built-in aggregate functions take values from an input table and aggregate them in some way. +title: Flux built-in aggregate transformations +list_title: Built-in aggregate transformations +description: > + Flux's aggregate transformations take values from an input table and aggregate them in some way. + Output tables contain a single row with the aggregated value. aliases: - /v2.0/reference/flux/functions/transformations/aggregates - /v2.0/reference/flux/functions/built-in/transformations/aggregates/ @@ -16,8 +18,8 @@ related: - /v2.0/query-data/flux/window-aggregate/ --- -Flux's built-in aggregate functions take values from an input table and aggregate them in some way. -The output table contains a single row with the aggregated value. +Flux's built-in aggregate transformations take values from an input table and aggregate them in some way. +Output tables contain a single row with the aggregated value. Aggregate operations output a table for every input table they receive. You must provide a column to aggregate. diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/chandemomentumoscillator.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/chandemomentumoscillator.md similarity index 85% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/chandemomentumoscillator.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/chandemomentumoscillator.md index e3e03218a..80a28bf23 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/chandemomentumoscillator.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/chandemomentumoscillator.md @@ -5,11 +5,12 @@ description: > developed by Tushar Chande. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/chandemomentumoscillator/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/chandemomentumoscillator/ menu: v2_0_ref: name: chandeMomentumOscillator - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/functions/#triple-exponential-moving-average, InfluxQL CHANDE_MOMENTUM_OSCILLATOR() --- @@ -17,7 +18,7 @@ related: The `chandeMomentumOscillator()` function applies the technical momentum indicator developed by Tushar Chande. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js chandeMomentumOscillator( @@ -45,10 +46,16 @@ Defaults to `["_value"]`. _**Data type: Array of Strings**_ +## Output tables +For each input table with `x` rows, `chandeMomentumOscillator()` outputs a table +with `x - n` rows. + ## Examples #### Table transformation with a ten point Chande Momentum Oscillator +{{< flex >}} +{{% flex-content %}} ###### Input table | _time | _value | |:-----:|:------:| @@ -81,7 +88,9 @@ _**Data type: Array of Strings**_ | 0027 | 3 | | 0028 | 2 | | 0029 | 1 | +{{% /flex-content %}} +{{% flex-content %}} ###### Query ```js // ... @@ -110,3 +119,5 @@ _**Data type: Array of Strings**_ | 0027 | -100 | | 0028 | -100 | | 0029 | -100 | +{{% /flex-content %}} +{{< /flex >}} diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/cov.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/cov.md similarity index 90% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/cov.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/cov.md index af138115a..6cf522572 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/cov.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/cov.md @@ -4,17 +4,18 @@ description: The `cov()` function computes the covariance between two streams by aliases: - /v2.0/reference/flux/functions/transformations/aggregates/cov - /v2.0/reference/flux/functions/built-in/transformations/aggregates/cov/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/cov/ menu: v2_0_ref: name: cov - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 --- The `cov()` function computes the covariance between two streams by first joining the streams, then performing the covariance operation. -_**Function type:** Aggregate +_**Function type:** Transformation_ _**Output data type:** Float_ ```js diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/covariance.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/covariance.md similarity index 86% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/covariance.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/covariance.md index f4e7ecbbc..7760f859b 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/covariance.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/covariance.md @@ -4,16 +4,17 @@ description: The `covariance()` function computes the covariance between two col aliases: - /v2.0/reference/flux/functions/transformations/aggregates/covariance - /v2.0/reference/flux/functions/built-in/transformations/aggregates/covariance/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/covariance/ menu: v2_0_ref: name: covariance - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 --- The `covariance()` function computes the covariance between two columns. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/derivative.md similarity index 84% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/derivative.md index 8594c0310..4b3a4c54d 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/derivative.md @@ -7,8 +7,10 @@ aliases: menu: v2_0_ref: name: derivative - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 +aliases: + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/derivative related: - /v2.0/query-data/flux/rate/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#derivative, InfluxQL – DERIVATIVE() @@ -18,7 +20,7 @@ The `derivative()` function computes the rate of change per [`unit`](#unit) of t It assumes rows are ordered by the `_time` column. The output table schema is the same as the input table. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js @@ -56,6 +58,9 @@ Defaults to `"_time"`. _**Data type:** String_ +## Output tables +For each input table with `n` rows, `derivative()` outputs a table with `n - 1` rows. + ## Examples ```js from(bucket: "example-bucket") diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/difference.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/difference.md similarity index 91% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/difference.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/difference.md index fb773a363..62948590f 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/difference.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/difference.md @@ -7,8 +7,10 @@ aliases: menu: v2_0_ref: name: difference - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 +aliases: + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/difference related: - https://docs.influxdata.com/influxdb/latest/query_language/functions/#difference, InfluxQL – DIFFERENCE() --- @@ -16,7 +18,7 @@ related: The `difference()` function computes the difference between subsequent records. The user-specified columns of numeric type are subtracted while others are kept intact. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js @@ -55,6 +57,8 @@ _**Data type:** Boolean_ - Some value `v` minus `null` is `v` minus the last non-null value seen before `v`; or `null` if `v` is the first non-null value seen. +## Output tables +For each input table with `n` rows, `difference()` outputs a table with `n - 1` rows. ## Examples diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/doubleema.md similarity index 83% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/doubleema.md index 54799e1e1..edf424696 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/doubleema.md @@ -6,16 +6,17 @@ description: > the rate of `exponentialMovingAverage()`. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ menu: v2_0_ref: name: doubleEMA - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#double-exponential-moving-average, InfluxQL DOUBLE_EXPONENTIAL_MOVING_AVERAGE() --- @@ -23,7 +24,7 @@ The `doubleEMA()` function calculates the exponential moving average of values i the `_value` column grouped into `n` number of points, giving more weight to recent data at double the rate of [`exponentialMovingAverage()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/). -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js doubleEMA(n: 5) diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage.md similarity index 84% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage.md index 960768f25..cbd7d8b32 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage.md @@ -5,16 +5,17 @@ description: > in the `_value` column grouped into `n` number of points, giving more weight to recent data. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ menu: v2_0_ref: name: exponentialMovingAverage - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/tripleema/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#exponential-moving-average, InfluxQL EXPONENTIAL_MOVING_AVERAGE() --- diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md index 77fc61f9c..abb897cad 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/group.md @@ -32,6 +32,19 @@ group(columns: ["_time"], mode:"except") group() ``` +{{% warn %}} +#### Group does not guarantee sort order +`group()` does not guarantee the sort order of output records. +To ensure data is sorted correctly, use [`sort()`](/v2.0/reference/flux/stdlib/built-in/transformations/sort/) +after `group()`. + +```js +data + |> group() + |> sort(columns: ["_time"]) +``` +{{% /warn %}} + ## Parameters ### columns diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/holtwinters.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/holtwinters.md similarity index 95% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/holtwinters.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/holtwinters.md index 7ad44ac11..75e855131 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/holtwinters.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/holtwinters.md @@ -5,18 +5,19 @@ description: > aliases: - /v2.0/reference/flux/functions/transformations/aggregates/holtwinters - /v2.0/reference/flux/functions/built-in/transformations/aggregates/holtwinters/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/holtwinters/ menu: v2_0_ref: name: holtWinters - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - https://docs.influxdata.com/influxdb/latest/query_language/functions/#holt-winters, InfluxQL HOLT_WINTERS() --- The `holtWinters()` function applies the Holt-Winters forecasting method to input tables. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/increase.md similarity index 80% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/increase.md index c1eba9af5..1481b6737 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/increase.md @@ -6,11 +6,12 @@ description: > aliases: - /v2.0/reference/flux/functions/transformations/aggregates/increase - /v2.0/reference/flux/functions/built-in/transformations/aggregates/increase/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/increase/ menu: v2_0_ref: name: increase - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - /v2.0/query-data/flux/increase/ --- @@ -22,7 +23,7 @@ when they hit a threshold or are reset. In the case of a wrap/reset, we can assume that the absolute delta between two points will be at least their non-negative difference. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js @@ -37,6 +38,9 @@ Defaults to `["_value"]`. _**Data type:** Array of strings_ +## Output tables +For each input table with `n` rows, `derivative()` outputs a table with `n - 1` rows. + ## Examples ```js from(bucket: "example-bucket") @@ -48,6 +52,8 @@ from(bucket: "example-bucket") |> increase() ``` +{{< flex >}} +{{% flex-content %}} Given the following input table: | _time | _value | @@ -56,7 +62,8 @@ Given the following input table: | 00002 | 5 | | 00003 | 3 | | 00004 | 4 | - +{{% /flex-content %}} +{{% flex-content %}} `increase()` produces the following table: | _time | _value | @@ -64,6 +71,8 @@ Given the following input table: | 00002 | 4 | | 00003 | 4 | | 00004 | 5 | +{{% /flex-content %}} +{{< /flex >}} ## Function definition ```js diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmansama.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmansama.md similarity index 87% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmansama.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmansama.md index 2d76e185d..fcc99a883 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmansama.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmansama.md @@ -5,20 +5,21 @@ description: > using values in an input table. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/kaufmansama/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmansama/ menu: v2_0_ref: name: kaufmansAMA - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmanser/ + - /v2.0/reference/flux/stdlib/built-in/transformations/kaufmanser/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#kaufmans-adaptive-moving-average, InfluxQL KAUFMANS_ADAPTIVE_MOVING_AVERAGE() --- The `kaufmansAMA()` function calculates the Kaufman's Adaptive Moving Average (KAMA) using values in an input table. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js kaufmansAMA( diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmanser.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmanser.md similarity index 86% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmanser.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmanser.md index cac7b51c2..87787238d 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmanser.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/kaufmanser.md @@ -5,13 +5,14 @@ description: > values in an input table. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/kaufmanser/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmanser/ menu: v2_0_ref: name: kaufmansER - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/kaufmansama/ + - /v2.0/reference/flux/stdlib/built-in/transformations/kaufmansama/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#kaufmans-efficiency-ratio, InfluxQL KAUFMANS_EFFICIENCY_RATIO() --- @@ -19,7 +20,7 @@ The `kaufmansER()` function calculates the Kaufman's Efficiency Ratio (KER) usin values in an input table. The function operates on the `_value` column. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js kaufmansER(n: 10) diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/movingaverage.md similarity index 77% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/movingaverage.md index cd8f97020..1fe3130ca 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/movingaverage.md @@ -4,24 +4,25 @@ description: > The `movingAverage()` function calculates the mean of values grouped into `n` number of points. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/movingaverage/ + - /v2.0/reference/flux/functions/built-in/transformations/movingaverage/ menu: v2_0_ref: name: movingAverage - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - /v2.0/query-data/flux/moving-average/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/tripleema/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() --- The `movingAverage()` function calculates the mean of values in the `_values` column grouped into `n` number of points. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js movingAverage(n: 5) diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/pearsonr.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/pearsonr.md similarity index 89% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/pearsonr.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/pearsonr.md index f5e4bc776..c3ac9d936 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/pearsonr.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/pearsonr.md @@ -4,17 +4,18 @@ description: The `pearsonr()` function computes the Pearson R correlation coeffi aliases: - /v2.0/reference/flux/functions/transformations/aggregates/pearsonr - /v2.0/reference/flux/functions/built-in/transformations/aggregates/pearsonr/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/pearsonr/ menu: v2_0_ref: name: pearsonr - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 --- The `pearsonr()` function computes the Pearson R correlation coefficient between two streams by first joining the streams, then performing the covariance operation normalized to compute R. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ _**Output data type:** Float_ ```js diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/relativestrengthindex.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/relativestrengthindex.md similarity index 82% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/relativestrengthindex.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/relativestrengthindex.md index 58a8cb856..42998011c 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/relativestrengthindex.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/relativestrengthindex.md @@ -5,22 +5,23 @@ description: > values in an input table. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/relativestrengthindex/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/relativestrengthindex/ menu: v2_0_ref: name: relativeStrengthIndex - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#relative-strength-index, InfluxQL RELATIVE_STRENGTH_INDEX() --- The `relativeStrengthIndex()` function measures the relative speed and change of values in an input table. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js relativeStrengthIndex( @@ -50,6 +51,10 @@ Columns to operate on. _Defaults to `["_value"]`_. _**Data type:** Array of Strings_ +## Output tables +For each input table with `x` rows, `relativeStrengthIndex()` outputs a table +with `x - n` rows. + ## Examples #### Calculate a five point relative strength index @@ -61,6 +66,8 @@ from(bucket: "example-bucket"): #### Table transformation with a ten point RSI +{{< flex >}} +{{% flex-content %}} ###### Input table: | _time | A | B | tag | |:-----:|:----:|:----:|:---:| @@ -82,7 +89,8 @@ from(bucket: "example-bucket"): | 0016 | 16 | 16 | tv | | 0017 | 17 | null | tv | | 0018 | 18 | 17 | tv | - +{{% /flex-content %}} +{{% flex-content %}} ###### Query: ```js // ... @@ -103,3 +111,5 @@ from(bucket: "example-bucket"): | 0016 | 90 | 90 | tv | | 0017 | 81 | 90 | tv | | 0018 | 72.9 | 81 | tv | +{{% flex-content %}} +{{< /flex >}} diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage.md similarity index 82% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage.md index 2d1b0be01..e65913828 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage.md @@ -5,23 +5,24 @@ description: > range at a specified frequency. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ menu: v2_0_ref: name: timedMovingAverage - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/tripleema/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#moving-average, InfluxQL MOVING_AVERAGE() --- The `timedMovingAverage()` function calculates the mean of values in a defined time range at a specified frequency. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js timedMovingAverage( diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/tripleema.md similarity index 85% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/tripleema.md index 140882c33..9810b3316 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/tripleema.md @@ -6,16 +6,17 @@ description: > than `exponentialMovingAverage()` and `doubleEMA()`. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ menu: v2_0_ref: name: tripleEMA - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#triple-exponential-moving-average, InfluxQL TRIPLE_EXPONENTIAL_MOVING_AVERAGE() --- @@ -25,7 +26,7 @@ data with less lag than [`exponentialMovingAverage()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/) and [`doubleEMA()`](/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/). -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js tripleEMA(n: 5) diff --git a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleexponentialderivative.md b/content/v2.0/reference/flux/stdlib/built-in/transformations/tripleexponentialderivative.md similarity index 83% rename from content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleexponentialderivative.md rename to content/v2.0/reference/flux/stdlib/built-in/transformations/tripleexponentialderivative.md index 9d6aee924..1ac8d5bc3 100644 --- a/content/v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleexponentialderivative.md +++ b/content/v2.0/reference/flux/stdlib/built-in/transformations/tripleexponentialderivative.md @@ -5,18 +5,19 @@ description: > derivative (TRIX) of input tables using `n` points. aliases: - /v2.0/reference/flux/functions/built-in/transformations/aggregates/tripleexponentialderivative/ + - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleexponentialderivative/ menu: v2_0_ref: name: tripleExponentialDerivative - parent: built-in-aggregates -weight: 501 + parent: built-in-transformations +weight: 402 v2.0/tags: [technical analysis] related: - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/movingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/doubleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/tripleema/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/timedmovingaverage/ - - /v2.0/reference/flux/stdlib/built-in/transformations/aggregates/exponentialmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/movingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/doubleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/tripleema/ + - /v2.0/reference/flux/stdlib/built-in/transformations/timedmovingaverage/ + - /v2.0/reference/flux/stdlib/built-in/transformations/exponentialmovingaverage/ - https://docs.influxdata.com/influxdb/latest/query_language/functions/#triple-exponential-derivative, InfluxQL TRIPLE_EXPONENTIAL_DERIVATIVE() --- @@ -24,7 +25,7 @@ The `tripleExponentialDerivative()` function calculates a triple exponential derivative ([TRIX](https://en.wikipedia.org/wiki/Trix_(technical_analysis))) of input tables using `n` points. -_**Function type:** Aggregate_ +_**Function type:** Transformation_ ```js tripleExponentialDerivative(n: 5) diff --git a/content/v2.0/reference/flux/stdlib/contrib/_index.md b/content/v2.0/reference/flux/stdlib/contrib/_index.md index 5355284b8..7051d3edb 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/_index.md @@ -5,7 +5,7 @@ description: > User-contributed packages and functions are contributed and maintained by members of the InfluxDB and Flux communities. menu: v2_0_ref: - name: User-contributed + name: Contributed parent: Flux standard library weight: 202 v2.0/tags: [contributed, functions, package] diff --git a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md index 7bff095dd..ecd131b2e 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md @@ -7,7 +7,7 @@ description: > menu: v2_0_ref: name: Discord - parent: User-contributed + parent: Contributed weight: 202 v2.0/tags: [functions, discord, package] --- diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md b/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md new file mode 100644 index 000000000..7d8cad01f --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/_index.md @@ -0,0 +1,32 @@ +--- +title: Flux Microsoft Teams package +list_title: Microsoft Teams package +description: > + The Flux Microsoft Teams package provides functions for sending messages to a + [Microsoft Teams](https://www.microsoft.com/microsoft-365/microsoft-teams/group-chat-software) + channel using an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook). + Import the `contrib/sranka/teams` package. +menu: + v2_0_ref: + name: Teams + parent: Contributed +weight: 202 +v2.0/tags: [functions, teams, microsoft, package] +--- + +The Flux Microsoft Teams package provides functions for sending messages to a +[Microsoft Teams](https://www.microsoft.com/microsoft-365/microsoft-teams/group-chat-software) +channel using an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook). +Import the `contrib/sranka/teams` package: + +```js +import "contrib/sranka/teams" +``` + +{{< children type="functions" show="pages" >}} + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md new file mode 100644 index 000000000..2f37e7e25 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/endpoint.md @@ -0,0 +1,78 @@ +--- +title: teams.endpoint() function +description: > + The `teams.endpoint()` function sends a message to a Microsoft Teams channel + using data from table rows. +menu: + v2_0_ref: + name: teams.endpoint + parent: Teams +weight: 202 +--- + +The `teams.endpoint()` function sends a message to a Microsoft Teams channel +using data from table rows. + +_**Function type:** Output_ + +```js +import "contrib/sranka/teams" + +teams.endpoint( + url: "https://outlook.office.com/webhook/example-webhook" +) +``` + +## Parameters + +### url +Incoming webhook URL. + +_**Data type:** String_ + +## Usage +`teams.endpoint` is a factory function that outputs another function. +The output function requires a `mapFn` parameter. + +### mapFn +A function that builds the object used to generate the POST request. +Requires an `r` parameter. + +_**Data type:** Function_ + +`mapFn` accepts a table row (`r`) and returns an object that must include the +following fields: + +- `title` +- `text` +- `summary` + +_For more information, see [`teams.message()`](/v2.0/reference/flux/stdlib/contrib/teams/message/)._ + +## Examples + +##### Send critical statuses to a Microsoft Teams channel +```js +import "contrib/sranka/teams" + +url = "https://outlook.office.com/webhook/example-webhook" +endpoint = teams.endpoint(url: url) + +crit_statuses = from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + +crit_statuses + |> endpoint(mapFn: (r) => ({ + title: "Disk Usage" + text: "Disk usage is: **${r.status}**.", + summary: "Disk usage is ${r.status}" + }) + ) +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/teams/message.md b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md new file mode 100644 index 000000000..f56bbc01b --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/teams/message.md @@ -0,0 +1,78 @@ +--- +title: teams.message() function +description: > + The `teams.message()` function sends a single message to a Microsoft Teams channel using + an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook). +menu: + v2_0_ref: + name: teams.message + parent: Teams +weight: 202 +--- + +The `teams.message()` function sends a single message to a Microsoft Teams channel using +an [incoming webhook](https://docs.microsoft.com/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook). + +_**Function type:** Output_ + +```js +import "contrib/sranka/teams" + +teams.message( + url: "https://outlook.office.com/webhook/example-webhook", + title: "Example message title", + text: "Example message text", + summary: "", +) +``` + +## Parameters + +### url +Incoming webhook URL. + +_**Data type:** String_ + +### title +Message card title. + +_**Data type:** String_ + +### text +Message card text. + +_**Data type:** String_ + +### summary +Message card summary. +Default is `""`. +If no summary is provided, Flux generates the summary from the message text. + +_**Data type:** String_ + +## Examples + +##### Send the last reported status to a Microsoft Teams channel +```js +import "contrib/sranka/teams" + +lastReported = + from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses") + |> last() + |> findRecord(fn: (key) => true, idx: 0) + +teams.message( + url: "https://outlook.office.com/webhook/example-webhook", + title: "Disk Usage" + text: "Disk usage is: *${lastReported.status}*.", + summary: "Disk usage is ${lastReported.status}" +) +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/telegram/_index.md b/content/v2.0/reference/flux/stdlib/contrib/telegram/_index.md new file mode 100644 index 000000000..6c2d2171a --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/telegram/_index.md @@ -0,0 +1,50 @@ +--- +title: Flux Telegram package +list_title: Telegram package +description: > + The Flux Telegram package provides functions for sending messages to + [Telegram](https://telegram.org/) using the [Telegram Bot API](https://core.telegram.org/bots/api). + Import the `contrib/sranka/telegram` package. +menu: + v2_0_ref: + name: Telegram + parent: Contributed +weight: 202 +v2.0/tags: [functions, teams, microsoft, package] +--- + +The Flux Telegram package provides functions for sending messages to +[Telegram](https://telegram.org/) using the [Telegram Bot API](https://core.telegram.org/bots/api). +Import the `contrib/sranka/telegram` package: + +```js +import "contrib/sranka/telegram" +``` + +{{< children type="functions" show="pages" >}} + +## Set up a Telegram bot +The **Telegram Bot API** requires a **bot token** and a **channel ID**. +To set up a Telegram bot and obtain the required bot token and channel ID: + +1. [Create a new Telegram account](https://telegram.org/) or use an existing account. +2. [Create a Telegram bot](https://core.telegram.org/bots#creating-a-new-bot). + Telegram provides a **bot token** for the newly created bot. +3. Use the **Telegram application** to create a new channel. +4. [Add the new bot to the channel](https://stackoverflow.com/questions/33126743/how-do-i-add-my-bot-to-a-channel) as an **Administrator**. + Ensure the bot has permissions necessary to **post messages**. +5. Send a message to bot in the channel. +6. Send a request to `https://api.telegram.org/bot$token/getUpdates`. + + ```sh + curl https://api.telegram.org/bot$token/getUpdates + ``` + + Find your **channel ID** in the `id` field of the response. + + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/telegram/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/telegram/endpoint.md new file mode 100644 index 000000000..4e5736adb --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/telegram/endpoint.md @@ -0,0 +1,106 @@ +--- +title: telegram.endpoint() function +description: > + The `telegram.endpoint()` function sends a message to a Telegram channel + using data from table rows. +menu: + v2_0_ref: + name: telegram.endpoint + parent: Telegram +weight: 202 +--- + +The `telegram.endpoint()` function sends a message to a Telegram channel +using data from table rows. + +_**Function type:** Output_ + +```js +import "contrib/sranka/telegram" + +telegram.endpoint( + url: "https://api.telegram.org/bot", + token: "S3crEtTel3gRamT0k3n", + parseMode: "MarkdownV2", + disableWebPagePreview: false, +) +``` + +{{% note %}} +For information about retrieving your Telegram **bot token** and **channel ID**, +see [Set up a Telegram bot](/v2.0/reference/flux/stdlib/contrib/telegram/#set-up-a-telegram-bot). +{{% /note %}} + +## Parameters + +### url +URL of the Telegram bot endpoint. +Default is `https://api.telegram.org/bot`. + +_**Data type:** String_ + +### token +Required +Telegram bot token. + +_**Data type:** String_ + +### parseMode +[Parse mode](https://core.telegram.org/bots/api#formatting-options) of the message text. +Default is `"MarkdownV2"`. + +_**Data type:** String_ + +### disableWebPagePreview +Disable preview of web links in the sent message. +Default is `false`. + +_**Data type:** Boolean_ + +## Usage +`telegram.endpoint` is a factory function that outputs another function. +The output function requires a `mapFn` parameter. + +### mapFn +A function that builds the object used to generate the POST request. +Requires an `r` parameter. + +_**Data type:** Function_ + +`mapFn` accepts a table row (`r`) and returns an object that must include the +following fields: + +- `channel` +- `text` +- `silent` + +_For more information, see [`telegram.message()`](/v2.0/reference/flux/stdlib/contrib/telegram/message/)._ + +## Examples + +##### Send critical statuses to a Telegram channel +```js +import "influxdata/influxdb/secrets" +import "contrib/sranka/telegram" + +token = secrets.get(key: "TELEGRAM_TOKEN") +endpoint = telegram.endpoint(token: token) + +crit_statuses = from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + +crit_statuses + |> endpoint(mapFn: (r) => ({ + channel: "-12345", + text: "Disk usage is **${r.status}**.", + silent: true + }) + ) +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/contrib/telegram/message.md b/content/v2.0/reference/flux/stdlib/contrib/telegram/message.md new file mode 100644 index 000000000..e9e074f91 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/telegram/message.md @@ -0,0 +1,107 @@ +--- +title: telegram.message() function +description: > + The `telegram.message()` function sends a single message to a Telegram channel using + the [`sendMessage` method of the Telegram Bot API](https://core.telegram.org/bots/api#sendmessage). +menu: + v2_0_ref: + name: telegram.message + parent: Telegram +weight: 202 +--- + +The `telegram.message()` function sends a single message to a Telegram channel using +the [`sendMessage` method of the Telegram Bot API](https://core.telegram.org/bots/api#sendmessage). + +_**Function type:** Output_ + +```js +import "contrib/sranka/telegram" + +telegram.message( + url: "https://api.telegram.org/bot", + token: "S3crEtTel3gRamT0k3n", + channel: "-12345", + text: "Example message text", + parseMode: "MarkdownV2", + disableWebPagePreview: false, + silent: true +) +``` + +{{% note %}} +For information about retrieving your Telegram **bot token** and **channel ID**, +see [Set up a Telegram bot](/v2.0/reference/flux/stdlib/contrib/telegram/#set-up-a-telegram-bot). +{{% /note %}} + +## Parameters + +### url +URL of the Telegram bot endpoint. +Default is `https://api.telegram.org/bot`. + +_**Data type:** String_ + +### token +Required +Telegram bot token. + +_**Data type:** String_ + +### channel +Required +Telegram channel ID. + +_**Data type:** String_ + +### text +Message text. + +_**Data type:** String_ + +### parseMode +[Parse mode](https://core.telegram.org/bots/api#formatting-options) of the message text. +Default is `"MarkdownV2"`. + +_**Data type:** String_ + +### disableWebPagePreview +Disable preview of web links in the sent message. +Default is `false`. + +_**Data type:** Boolean_ + +### silent +Send message [silently](https://telegram.org/blog/channels-2-0#silent-messages). +Default is `true`. + +_**Data type:** Boolean_ + +## Examples + +##### Send the last reported status to a Microsoft Teams channel +```js +import "influxdata/influxdb/secrets" +import "contrib/sranka/telegram" + +token = secrets.get(key: "TELEGRAM_TOKEN") + +lastReported = + from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses") + |> last() + |> findRecord(fn: (key) => true, idx: 0) + + telegram.message( + token: token, + channel: "-12345" + text: "Disk usage is **${lastReported.status}**.", + ) +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@sranka](https://github.com/sranka) +**InfluxDB Slack:** [@sranka](https://influxdata.com/slack) +{{% /note %}} diff --git a/content/v2.0/reference/flux/stdlib/date/hour.md b/content/v2.0/reference/flux/stdlib/date/hour.md index efdf143e7..02bde42e7 100644 --- a/content/v2.0/reference/flux/stdlib/date/hour.md +++ b/content/v2.0/reference/flux/stdlib/date/hour.md @@ -29,5 +29,29 @@ date.hour(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the hour of a time value +```js +import "date" + +date.hour(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 12 +``` + +##### Return the hour of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.hour(t: -8h) + +// Returns 4 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/microsecond.md b/content/v2.0/reference/flux/stdlib/date/microsecond.md index bd4cbba76..3b6def9d0 100644 --- a/content/v2.0/reference/flux/stdlib/date/microsecond.md +++ b/content/v2.0/reference/flux/stdlib/date/microsecond.md @@ -29,5 +29,29 @@ date.microsecond(t: 2019-07-17T12:05:21.012934584Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the microsecond of a time value +```js +import "date" + +date.microsecond(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 293534 +``` + +##### Return the microsecond of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.microsecond(t: -1890us) + +// Returns 291644 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/millisecond.md b/content/v2.0/reference/flux/stdlib/date/millisecond.md index 6d7a6285e..31496d092 100644 --- a/content/v2.0/reference/flux/stdlib/date/millisecond.md +++ b/content/v2.0/reference/flux/stdlib/date/millisecond.md @@ -29,5 +29,29 @@ date.millisecond(t: 2019-07-17T12:05:21.012934584Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the millisecond of a time value +```js +import "date" + +date.millisecond(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 293 +``` + +##### Return the millisecond of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.millisecond(t: -150ms) + +// Returns 143 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/minute.md b/content/v2.0/reference/flux/stdlib/date/minute.md index 5e5ec0b34..d1e9db92c 100644 --- a/content/v2.0/reference/flux/stdlib/date/minute.md +++ b/content/v2.0/reference/flux/stdlib/date/minute.md @@ -29,5 +29,29 @@ date.minute(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the minute of a time value +```js +import "date" + +date.minute(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 21 +``` + +##### Return the minute of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.minute(t: -45m) + +// Returns 36 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/month.md b/content/v2.0/reference/flux/stdlib/date/month.md index 6612dedd4..01330e261 100644 --- a/content/v2.0/reference/flux/stdlib/date/month.md +++ b/content/v2.0/reference/flux/stdlib/date/month.md @@ -29,5 +29,29 @@ date.month(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the month of a time value +```js +import "date" + +date.month(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 2 +``` + +##### Return the month of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.month(t: -3mo) + +// Returns 11 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/monthday.md b/content/v2.0/reference/flux/stdlib/date/monthday.md index fabc7d31b..36684343f 100644 --- a/content/v2.0/reference/flux/stdlib/date/monthday.md +++ b/content/v2.0/reference/flux/stdlib/date/monthday.md @@ -29,5 +29,29 @@ date.monthDay(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the day of the month for a time value +```js +import "date" + +date.monthDay(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 11 +``` + +##### Return the day of the month for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.monthDay(t: -8d) + +// Returns 3 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/nanosecond.md b/content/v2.0/reference/flux/stdlib/date/nanosecond.md index 9d05b1f72..846aa0129 100644 --- a/content/v2.0/reference/flux/stdlib/date/nanosecond.md +++ b/content/v2.0/reference/flux/stdlib/date/nanosecond.md @@ -29,5 +29,29 @@ date.nanosecond(t: 2019-07-17T12:05:21.012934584Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the nanosecond for a time value +```js +import "date" + +date.nanosecond(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 293534940Z +``` + +##### Return the nanosecond for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.nanosecond(t: -2111984ns) + +// Returns 291422956 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/quarter.md b/content/v2.0/reference/flux/stdlib/date/quarter.md index a2f05b0f9..5a225a4a9 100644 --- a/content/v2.0/reference/flux/stdlib/date/quarter.md +++ b/content/v2.0/reference/flux/stdlib/date/quarter.md @@ -29,5 +29,29 @@ date.quarter(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the quarter for a time value +```js +import "date" + +date.quarter(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 1 +``` + +##### Return the quarter for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.quarter(t: -7mo) + +// Returns 3 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/second.md b/content/v2.0/reference/flux/stdlib/date/second.md index e7cc28f7f..33493d457 100644 --- a/content/v2.0/reference/flux/stdlib/date/second.md +++ b/content/v2.0/reference/flux/stdlib/date/second.md @@ -29,5 +29,29 @@ date.second(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the second of a time value +```js +import "date" + +date.second(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 3 +``` + +##### Return the second of a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.second(t: -50s) + +// Returns 13 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/truncate.md b/content/v2.0/reference/flux/stdlib/date/truncate.md index 762cfffcd..f2ef1cb3b 100644 --- a/content/v2.0/reference/flux/stdlib/date/truncate.md +++ b/content/v2.0/reference/flux/stdlib/date/truncate.md @@ -30,8 +30,10 @@ date.truncate( ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ ### unit The unit of time to truncate to. @@ -44,16 +46,33 @@ For example: `1s`, `1m`, `1h`. {{% /note %}} ## Examples + +##### Truncate time values ```js import "date" -date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1s) -// Returns 2019-06-03T13:59:01.000000000Z +date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1s) +// Returns 2019-06-03T13:59:01.000000000Z -date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1m) -// Returns 2019-06-03T13:59:00.000000000Z - -date.truncate(t: "2019-06-03T13:59:01.000000000Z", unit: 1h) -// Returns 2019-06-03T13:00:00.000000000Z +date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1m) +// Returns 2019-06-03T13:59:00.000000000Z +date.truncate(t: 2019-06-03T13:59:01.000000000Z, unit: 1h) +// Returns 2019-06-03T13:00:00.000000000Z +``` + +##### Truncate time values using durations +```js +import "date" + +option now = () => 2020-01-01T00:00:30.500000000Z + +date.truncate(t: -30s, unit: 1s) +// Returns 2019-12-31T23:59:30.000000000Z + +date.truncate(t: -1m, unit: 1m) +// Returns 2019-12-31T23:59:00.000000000Z + +date.truncate(t: -1h, unit: 1h) +// Returns 2019-12-31T23:00:00.000000000Z ``` diff --git a/content/v2.0/reference/flux/stdlib/date/week.md b/content/v2.0/reference/flux/stdlib/date/week.md index dec8bddec..d508e7c10 100644 --- a/content/v2.0/reference/flux/stdlib/date/week.md +++ b/content/v2.0/reference/flux/stdlib/date/week.md @@ -29,5 +29,29 @@ date.week(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the week of the year +```js +import "date" + +date.week(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 7 +``` + +##### Return the week of the year using a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.week(t: -12d) + +// Returns 5 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/weekday.md b/content/v2.0/reference/flux/stdlib/date/weekday.md index 6e6fdb18c..0afcf7c67 100644 --- a/content/v2.0/reference/flux/stdlib/date/weekday.md +++ b/content/v2.0/reference/flux/stdlib/date/weekday.md @@ -29,5 +29,29 @@ date.weekDay(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the day of the week for a time value +```js +import "date" + +date.weekDay(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 2 +``` + +##### Return the day of the week for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.weekDay(t: -84h) + +// Returns 6 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/year.md b/content/v2.0/reference/flux/stdlib/date/year.md index f911a5976..fd452ed2f 100644 --- a/content/v2.0/reference/flux/stdlib/date/year.md +++ b/content/v2.0/reference/flux/stdlib/date/year.md @@ -27,5 +27,29 @@ date.year(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the year for a time value +```js +import "date" + +date.year(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 2020 +``` + +##### Return the year for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.year(t: -14y) + +// Returns 2006 +``` diff --git a/content/v2.0/reference/flux/stdlib/date/yearday.md b/content/v2.0/reference/flux/stdlib/date/yearday.md index 20df57afe..a7ff048fb 100644 --- a/content/v2.0/reference/flux/stdlib/date/yearday.md +++ b/content/v2.0/reference/flux/stdlib/date/yearday.md @@ -29,5 +29,29 @@ date.yearDay(t: 2019-07-17T12:05:21.012Z) ### t The time to operate on. +Use an absolute time or relative duration. +Durations are relative to `now()`. -_**Data type:** Time_ +_**Data type:** Time | Duration_ + +## Examples + +##### Return the day of the year for a time value +```js +import "date" + +date.yearDay(t: 2020-02-11T12:21:03.293534940Z) + +// Returns 42 +``` + +##### Return the day of the year for a relative duration +```js +import "date" + +option now = () => 2020-02-11T12:21:03.293534940Z + +date.yearDay(t: -1mo) + +// Returns 11 +``` diff --git a/content/v2.0/reference/flux/stdlib/sql/_index.md b/content/v2.0/reference/flux/stdlib/sql/_index.md index 2fd8814e0..53dadf6c5 100644 --- a/content/v2.0/reference/flux/stdlib/sql/_index.md +++ b/content/v2.0/reference/flux/stdlib/sql/_index.md @@ -3,7 +3,7 @@ title: Flux SQL package list_title: SQL package description: > The Flux SQL package provides tools for working with data in SQL databases such - as MySQL, PostgreSQL, and SQLite. + as MySQL, PostgreSQL, Snowflake, SQLite, Microsoft SQL Server, and Amazon Athena. Import the `sql` package. aliases: - /v2.0/reference/flux/functions/sql/ @@ -17,8 +17,15 @@ related: - /v2.0/query-data/flux/sql/ --- -SQL Flux functions provide tools for working with data in SQL databases such as -MySQL, PostgreSQL, Snowflake, and SQLite. +SQL Flux functions provide tools for working with data in SQL databases such as: + +- Amazon Athena +- Microsoft SQL Server +- MySQL +- PostgreSQL +- Snowflake +- SQLite + Import the `sql` package: ```js diff --git a/content/v2.0/reference/flux/stdlib/sql/from.md b/content/v2.0/reference/flux/stdlib/sql/from.md index 0ecc56666..f48d16a92 100644 --- a/content/v2.0/reference/flux/stdlib/sql/from.md +++ b/content/v2.0/reference/flux/stdlib/sql/from.md @@ -35,10 +35,12 @@ _**Data type:** String_ The following drivers are available: +- awsathena - mysql - postgres - snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#query-an-sqlite-database)._ +- sqlserver, mssql ### dataSourceName The data source name (DSN) or connection string used to connect to the SQL database. @@ -48,12 +50,16 @@ _**Data type:** String_ ##### Driver dataSourceName examples ```sh -# Postgres Driver DSN -postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full +# Amazon Athena Driver DSN +s3://myorgqueryresults/?accessID=AKIAJLO3F...®ion=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F... +s3://myorgqueryresults/?accessID=AKIAJLO3F...&db=dbname&missingAsDefault=false&missingAsEmptyString=false®ion=us-west-1&secretAccessKey=NnQ7MUMp9PYZsmD47c%2BSsXGOFsd%2F...&WGRemoteCreation=false # MySQL Driver DSN username:password@tcp(localhost:3306)/dbname?param=value +# Postgres Driver DSN +postgres://pqgotest:password@localhost/pqgotest?sslmode=verify-full + # Snowflake Driver DSNs username[:password]@accountname/dbname/schemaname?param1=value1¶mN=valueN username[:password]@accountname/dbname?param1=value1¶mN=valueN @@ -61,6 +67,12 @@ username[:password]@hostname:port/dbname/schemaname?account=¶m # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=ro + +# Microsoft SQL Server Driver DSNs +sqlserver://username:password@localhost:1234?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=0123456789 ``` ### query @@ -70,6 +82,13 @@ _**Data type:** String_ ## Examples +- [MySQL](#query-a-mysql-database) +- [Postgres](#query-a-postgres-database) +- [Snowflake](#query-a-snowflake-database) +- [SQLite](#query-an-sqlite-database) +- [Amazon Athena](#query-an-amazon-athena-database) +- [SQL Server](#query-a-sql-server-database) + {{% note %}} The examples below use [InfluxDB secrets](/v2.0/security/secrets/) to populate sensitive connection credentials. @@ -139,3 +158,95 @@ sql.from( query: "SELECT * FROM example_table" ) ``` + +### Query an Amazon Athena database +```js +import "sql" +import "influxdata/influxdb/secrets" + +region = us-west-1 +accessID = secrets.get(key: "ATHENA_ACCESS_ID") +secretKey = secrets.get(key: "ATHENA_SECRET_KEY") + +sql.from( + driverName: "awsathena", + dataSourceName: "s3://myorgqueryresults/?accessID=${accessID}®ion=${region}&secretAccessKey=${secretKey}", + query:"SELECT * FROM example_table" +) +``` + +##### Athena connection string +To query an Amazon Athena database, use the following query parameters in your Athena +S3 connection string (DSN): + +\* Required + +- **region** - AWS region \* +- **accessID** - AWS IAM access ID \* +- **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 + + +### Query a SQL Server database +```js +import "sql" +import "influxdata/influxdb/secrets" + +username = secrets.get(key: "SQLSERVER_USER") +password = secrets.get(key: "SQLSERVER_PASS") + +sql.from( + driverName: "sqlserver", + dataSourceName: "sqlserver://${username}:${password}@localhost:1234?database=examplebdb", + query: "GO SELECT * FROM Example.Table" +) +``` + +#### 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) +connection string 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 connection string](#specify-authentication-credentials-in-the-connection-string) +- [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 %}} +**InfluxDB OSS** and **{{< cloud-name "short" >}}** user interfaces do _**not**_ provide +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](/v2.0/reference/cli/influx/repl/) on your local machine. +{{% /warn %}} + +```powershel +azure auth=C:\secure\azure.auth +``` + +##### Specify authentication credentials in the connection string +```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 +``` diff --git a/content/v2.0/reference/flux/stdlib/sql/to.md b/content/v2.0/reference/flux/stdlib/sql/to.md index 4d94200ef..0dc69b006 100644 --- a/content/v2.0/reference/flux/stdlib/sql/to.md +++ b/content/v2.0/reference/flux/stdlib/sql/to.md @@ -38,6 +38,7 @@ The following drivers are available: - postgres - snowflake - sqlite3 – _Does not work with InfluxDB OSS or InfluxDB Cloud. More information [below](#write-data-to-an-sqlite-database)._ +- sqlserver, mssql ### dataSourceName The data source name (DSN) or connection string used to connect to the SQL database. @@ -60,6 +61,12 @@ username[:password]@hostname:port/dbname/schemaname?account=¶m # SQLite Driver DSN file:/path/to/test.db?cache=shared&mode=rw + +# Microsoft SQL Server Driver DSNs +sqlserver://username:password@localhost:1234?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=0123456789 ``` ### table @@ -79,6 +86,12 @@ If writing to a **SQLite** database, set `batchSize` to `999` or less. ## Examples +- [MySQL](#write-data-to-a-mysql-database) +- [Postgres](#write-data-to-a-postgres-database) +- [Snowflake](#write-data-to-a-snowflake-database) +- [SQLite](#write-data-to-an-sqlite-database) +- [SQL Server](#write-data-to-a-sql-server-database) + {{% note %}} The examples below use [InfluxDB secrets](/v2.0/security/secrets/) to populate sensitive connection credentials. @@ -148,3 +161,69 @@ sql.to( table: "example_table" ) ``` + +### Write data to a SQL Server database +```js +import "sql" +import "influxdata/influxdb/secrets" + +username = secrets.get(key: "SQLSERVER_USER") +password = secrets.get(key: "SQLSERVER_PASS") + +sql.to( + driverName: "sqlserver", + dataSourceName: "sqlserver://${username}:${password}@localhost:1234?database=examplebdb", + table: "Example.Table" +) +``` + +#### 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) +connection string 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 connection string](#specify-authentication-credentials-in-the-connection-string) +- [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 %}} +**InfluxDB OSS** and **{{< cloud-name "short" >}}** user interfaces do _**not**_ provide +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](/v2.0/reference/cli/influx/repl/) on your local machine. +{{% /warn %}} + +```powershell +azure auth=C:\secure\azure.auth +``` + +##### Specify authentication credentials in the connection string +```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 +``` + +{{% warn %}} +### sql.to does not support Amazon Athena +The `sql.to` function does not support writing data to [Amazon Athena](https://aws.amazon.com/athena/). +{{% /warn %}} diff --git a/content/v2.0/reference/release-notes/flux.md b/content/v2.0/reference/release-notes/flux.md index ed3c14153..4bd6fd2d2 100644 --- a/content/v2.0/reference/release-notes/flux.md +++ b/content/v2.0/reference/release-notes/flux.md @@ -16,6 +16,28 @@ Though newer versions of Flux may be available, they will not be included with InfluxDB until the next InfluxDB v2.0 release._ {{% /note %}} +## v0.70.0 [2020-06-29] +### Features +- Update all `date` functions to accept time and duration types. +- Add [Microsoft Teams package](/v2.0/reference/flux/stdlib/contrib/teams/). +- Evaluate and store `now` in execution dependencies for `tableFind()`. +- Add `Timeable` constraint for time and duration types. +- Add [SQL Server support](/v2.0/reference/flux/stdlib/sql/from/#query-a-sql-server-database) to `sql` package. +- Add [Telegram package](/v2.0/reference/flux/stdlib/contrib/telegram/). +- Add [Amazon Athena support](/v2.0/reference/flux/stdlib/sql/from/#query-an-amazon-athena-database) to `sql` package. +- Add support for macOS builds. + +### Bug fixes +- Move semantic analysis to the finalize step. +- Fix check for stream equality. +- Fix the compiler's return type when `with` operator is used. +- Include `stdlib` Flux dependencies from the Flux `build.rs`. +- Include a hash of the sources for `libflux`. +- Flux test for [experimental `json.parse()`](/v2.0/reference/flux/stdlib/experimental/json/parse/). +- Reorder `go generate` call to `libflux` in `stdlib`. + +--- + ## v0.69.2 [2020-06-10] ### Bug fixes