From 180a22d42835fd1f9610ce7f8cfa72aa176cc031 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 20 Jul 2020 09:16:31 -0600 Subject: [PATCH 1/4] added placeholder flux 0.74.0 release notes --- content/v2.0/reference/release-notes/flux.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/content/v2.0/reference/release-notes/flux.md b/content/v2.0/reference/release-notes/flux.md index 97f4020a4..dd74685c7 100644 --- a/content/v2.0/reference/release-notes/flux.md +++ b/content/v2.0/reference/release-notes/flux.md @@ -16,6 +16,12 @@ Though newer versions of Flux may be available, they will not be included with InfluxDB until the next InfluxDB v2.0 release._ {{% /note %}} +## v0.74.0 [unreleased] + +_placeholder_ + +--- + ## v0.73.0 [2020-07-13] ### Features From 01b57287125c7f292482d485c9083cecb61850cc Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 20 Jul 2020 14:28:45 -0600 Subject: [PATCH 2/4] Added discord.endpoint function, resolves #1218 --- .../flux/stdlib/contrib/discord/_index.md | 4 +- .../flux/stdlib/contrib/discord/endpoint.md | 99 +++++++++++++++++++ 2 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md 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 ecd131b2e..f7ed590d1 100644 --- a/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/_index.md @@ -2,7 +2,7 @@ title: Flux Discord package list_title: Discord package description: > - The Flux Discord package provides functions for sending data to Discord. + The Flux Discord package provides functions for sending messages to Discord. Import the `contrib/chobbs/discord` package. menu: v2_0_ref: @@ -12,7 +12,7 @@ weight: 202 v2.0/tags: [functions, discord, package] --- -The Flux Discord package provides functions for sending data to Discord. +The Flux Discord package provides functions for sending messages to Discord. Import the `contrib/chobbs/discord` package: ```js diff --git a/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md b/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md new file mode 100644 index 000000000..9e0d59ea7 --- /dev/null +++ b/content/v2.0/reference/flux/stdlib/contrib/discord/endpoint.md @@ -0,0 +1,99 @@ +--- +title: discord.endpoint() function +description: > + The `discord.endpoint()` function sends a single message to a Discord channel using + a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&?page=3) + and data from table rows. +menu: + v2_0_ref: + name: discord.endpoint + parent: Discord +weight: 202 +--- + +The `discord.endpoint()` function sends a single message to a Discord channel using +a [Discord webhook](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks&?page=3) +and data from table rows. + +_**Function type:** Output_ + +```js +import "contrib/chobbs/discord" + +discord.endpoint( + webhookToken: "mySuPerSecRetTokEn", + webhookID: "123456789", + username: "username", + avatar_url: "https://example.com/avatar_pic.jpg" +) +``` + +## Parameters + +### webhookToken +Discord [webhook token](https://discord.com/developers/docs/resources/webhook). + +_**Data type:** String_ + +### webhookID +Discord [webhook ID](https://discord.com/developers/docs/resources/webhook). + +_**Data type:** String_ + +### username +Override the Discord webhook's default username. + +_**Data type:** String_ + +### avatar_url +Override the Discord webhook's default avatar. + +_**Data type:** String_ + +## Usage +`discord.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 Discord webhook request. +Requires an `r` parameter. + +_**Data type:** Function_ + +`mapFn` accepts a table row (`r`) and returns an object that must include the +following field: + +- `content` + +_For more information, see the [`discord.send() content` parameter](/v2.0/reference/flux/stdlib/contrib/discord/send/#content)._ + +## Examples + +##### Send critical statuses to a Discord channel +```js +import "influxdata/influxdb/secrets" +import "contrib/chobbs/discord" + +discordToken = secrets.get(key: "DISCORD_TOKEN") +endpoint = telegram.endpoint( + webhookToken: discordToken, + webhookID: "123456789", + username: "critBot" +) + +crit_statuses = from(bucket: "example-bucket") + |> range(start: -1m) + |> filter(fn: (r) => r._measurement == "statuses" and status == "crit") + +crit_statuses + |> endpoint(mapFn: (r) => ({ + content: "The status is critical!", + }) + )() +``` + +{{% note %}} +#### Package author and maintainer +**Github:** [@chobbs](https://github.com/chobbs) +**InfluxDB Slack:** [@craig](https://influxdata.com/slack) +{{% /note %}} From 6d7328c91e45bdd1ccd1e5157493f311cc5dfb96 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Mon, 20 Jul 2020 15:53:40 -0600 Subject: [PATCH 3/4] update flux type grammar, resolves #1215 --- .../reference/flux/language/statements.md | 81 ------------------- .../flux/language/system-built-ins.md | 24 +++++- content/v2.0/reference/flux/language/types.md | 49 ++++++++++- 3 files changed, 69 insertions(+), 85 deletions(-) diff --git a/content/v2.0/reference/flux/language/statements.md b/content/v2.0/reference/flux/language/statements.md index 7a83d5ee8..a03bbd9c2 100644 --- a/content/v2.0/reference/flux/language/statements.md +++ b/content/v2.0/reference/flux/language/statements.md @@ -79,84 +79,3 @@ ExpressionStatement = Expression . f() a ``` - -## Named types - -A named type can be created using a type assignment statement. -A named type is equivalent to the type it describes and may be used interchangeably. - -```js -TypeAssignment = "type" identifier "=" TypeExpression . -TypeExpression = identifier - | TypeParameter - | ObjectType - | ArrayType - | GeneratorType - | FunctionType . -TypeParameter = "'" identifier . -ObjectType = "{" PropertyTypeList [";" ObjectUpperBound ] "}" . -ObjectUpperBound = "any" | PropertyTypeList . -PropertyTypeList = PropertyType [ "," PropertyType ] . -PropertyType = identifier ":" TypeExpression - | string_lit ":" TypeExpression . -ArrayType = "[]" TypeExpression . -GeneratorType = "[...]" TypeExpression . -FunctionType = ParameterTypeList "->" TypeExpression -ParameterTypeList = "(" [ ParameterType { "," ParameterType } ] ")" . -ParameterType = identifier ":" [ pipe_receive_lit ] TypeExpression . -``` - -Named types are a separate namespace from values. -It is possible for a value and a type to have the same identifier. -The following named types are built-in. - -```js -bool // boolean -int // integer -uint // unsigned integer -float // floating point number -duration // duration of time -time // time -string // utf-8 encoded string -regexp // regular expression -bytes // sequence of byte values -type // a type that itself describes a type -``` - -When an object's upper bound is not specified, it is assumed to be equal to its lower bound. - -Parameters to function types define whether the parameter is a pipe forward -parameter and whether the parameter has a default value. -The `<-` indicates the parameter is the pipe forward parameter. - -###### Examples -```js - // alias the bool type - type boolean = bool - - // define a person as an object type - type person = { - name: string, - age: int, - } - - // Define addition on ints - type intAdd = (a: int, b: int) -> int - - // Define polymorphic addition - type add = (a: 'a, b: 'a) -> 'a - - // Define funcion with pipe parameter - type bar = (foo: <-string) -> string - - // Define object type with an empty lower bound and an explicit upper bound - type address = { - ; - street: string, - city: string, - state: string, - country: string, - province: string, - zip: int, - } -``` diff --git a/content/v2.0/reference/flux/language/system-built-ins.md b/content/v2.0/reference/flux/language/system-built-ins.md index ae519868d..a542bb8b9 100644 --- a/content/v2.0/reference/flux/language/system-built-ins.md +++ b/content/v2.0/reference/flux/language/system-built-ins.md @@ -12,15 +12,35 @@ menu: weight: 206 --- +Flux contains many preassigned values. These preassigned values are defined in the source files for the various built-in packages. + When a built-in value is not expressible in Flux, its value may be defined by the hosting environment. All such values must have a corresponding builtin statement to declare the existence and type of the built-in value. ```js -BuiltinStatement = "builtin" identifier ":" TypeExpression . +BuiltinStatement = "builtin" identifer ":" TypeExpression . +TypeExpression = MonoType ["where" Constraints] . + +MonoType = Tvar | Basic | Array | Record | Function . +Tvar = "A" … "Z" . +Basic = "int" | "uint" | "float" | "string" | "bool" | "time" | "duration" | "bytes" | "regexp" . +Array = "[" MonoType "]" . +Record = ( "{" [Properties] "}" ) | ( "{" Tvar "with" Properties "}" ) . +Function = "(" [Parameters] ")" "=>" MonoType . + +Properties = Property { "," Property } . +Property = identifier ":" MonoType . + +Parameters = Parameter { "," Parameter } . +Parameter = [ "<-" | "?" ] identifier ":" MonoType . + +Constraints = Constraint { "," Constraint } . +Constraint = Tvar ":" Kinds . +Kinds = identifier { "+" identifier } . ``` ##### Example ```js -builtin from : (bucket: string, bucketID: string) -> stream +builtin filter : (<-tables: [T], fn: (r: T) -> bool) -> [T] ``` diff --git a/content/v2.0/reference/flux/language/types.md b/content/v2.0/reference/flux/language/types.md index 2a273b15e..67ee26b39 100644 --- a/content/v2.0/reference/flux/language/types.md +++ b/content/v2.0/reference/flux/language/types.md @@ -14,9 +14,10 @@ Any section that is not currently implemented is commented with a **[IMPL#XXX]** **XXX** is an issue number tracking discussion and progress towards implementation. {{% /note %}} -A _type_ defines the set of values and operations on those values. -Types are never explicitly declared as part of the syntax. +A **type** defines the set of values and operations on those values. +Types are never explicitly declared as part of the syntax except as part of a [builtin statement](#system-built-ins). Types are always inferred from the usage of the value. +Type inference follows a Hindley-Milner style inference system. ## Union types A union type defines a set of types. @@ -154,3 +155,47 @@ The generated values may be of any other type, but must all be the same type. {{% note %}} [IMPL#658](https://github.com/influxdata/platform/query/issues/658) Implement Generators types. {{% /note %}} + +#### Polymorphism +Flux types can be polymorphic, meaning that a type may take on many different types. +Flux supports let-polymorphism and structural polymorphism. + +##### Let-polymorphism +Let-polymorphism is the concept that each time an identifier is referenced, it may take on a different type. +For example: + +```js +add = (a,b) => a + b +add(a:1,b:2) // 3 +add(a:1.5,b:2.0) // 3.5 +``` + +The identifiers, `a` and `b`, in the body of the `add` function are used as both `int` and `float` types. + +##### Structural polymorphism +Structural polymorphism is the concept that structures (objects in Flux) can be +used by the same function even if the structures themselves are different. +For example: + +```js +john = {name:"John", lastName:"Smith"} +jane = {name:"Jane", age:44} + +// John and Jane are objects with different types. +// We can still define a function that can operate on both objects safely. + +// name returns the name of a person +name = (person) => person.name + +name(person:john) // John +name(person:jane) // Jane + +device = {id: 125325, lat: 15.6163, lon: 62.6623} + +name(person:device) // Type error, "device" does not have a property name. +``` + +Objects of differing types can be used as the same type so long as they both contain the necessary properties. +Necessary properties are determined by the use of the object. +This form of polymorphism means that checks are performed during type inference and not during runtime. +Type errors are found and reported before runtime. From d72779a8d092da401548a422d5da66be6f5c6816 Mon Sep 17 00:00:00 2001 From: Scott Anderson Date: Tue, 21 Jul 2020 09:32:53 -0600 Subject: [PATCH 4/4] added flux 0.74 release notes --- content/v2.0/reference/release-notes/flux.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/content/v2.0/reference/release-notes/flux.md b/content/v2.0/reference/release-notes/flux.md index dd74685c7..f2cc8e73f 100644 --- a/content/v2.0/reference/release-notes/flux.md +++ b/content/v2.0/reference/release-notes/flux.md @@ -16,9 +16,20 @@ Though newer versions of Flux may be available, they will not be included with InfluxDB until the next InfluxDB v2.0 release._ {{% /note %}} -## v0.74.0 [unreleased] +## v0.74.0 [2020-07-21] -_placeholder_ +### Features +- Add `discord.endpoint()` function. +- Enhance the static table API. +- Update `mod.rs` with `parse_type_expression` and other supporting functions. +- Expose static table package and table diff functions. +- `Find_var_type()` API. +- Add `stringify` method for a table and a diff utility. +- Added range to end-to-end tests. +- Add types grammar to SPEC. + +### Bug fixes +- Normalize Monotype. ---