Documentation

函数类型签名

A 函数类型签名 描述了一个函数的输入参数和类型,以及函数的输出类型。使用类型签名来识别函数参数期望的数据类型,并理解函数的预期输出。

函数类型签名结构

(parameter: type) => output-type

参数符号

参数符号表示函数参数的特定行为。

?  // Optional parameter
<- // Pipe receive – indicates the parameter that, by default, represents
   // the piped-forward value

类型变量

Flux 类型签名使用 类型变量 来表示签名中的唯一类型。类型变量是 多态的,这意味着它可以是多种类型之一,并且可能受到 类型约束 的限制。

类型变量使用以下标识符模式:

A
B
C
t11
// etc.

类型符号

流类型

类型签名使用 stream[A] 语法来识别流类型 (表的流),其中 A 是一个唯一的 类型变量。流类型可以包含特定的列名和列类型。

// Stream of tables
stream[A]

// Stream of tables with specific columns, but inferred column types.
stream[{col1: A, col2: B}]

// Stream of tables additional or required "count" column with an
// explicit integer type.
stream[{A with count: int}]

基本类型

类型签名通过以下类型标识符标识基本类型

bool     // boolean type
bytes    // bytes type
duration // duration type
float    // float type
int      // integer type
regexp   // regular expression type
string   // string type
time     // time type
uint     // unsigned integer type

复合类型

类型签名识别 Flux 复合类型,其语法如下:

[A]             // array type
[B: A]          // dictionary type
(param: A) => B // function type
{_value: int}   // record type

类型约束

某些函数参数是“多态的”,可以支持多种数据类型。 多态参数受类型约束的限制,这些约束定义了可以使用哪些类型。 类型签名使用where A: Constraint语法指示特定值的类型约束。

例如,以下类型签名描述了一个接受单个参数的函数,v 并返回一个整数。v 可以是满足 Timeable 约束的任何类型(持续时间或时间)。

(v: A) => int where A: Timeable

有关不同类型约束及其支持的类型的更多信息,请参见 Type constraints

示例函数类型签名


无参数的函数

以下类型签名描述了一个函数:

  • 没有参数
  • 返回一个时间值
() => time

带参数的函数

以下类型签名描述了一个函数:

  • 具有两个类型为 A 的参数:
    • multiplier (可选)
    • v (必需)
  • 返回与两个输入参数相同类型的值
(?multiplier: A, v: A) => A

透传转换

以下类型签名描述了一个 转换

  • 接受类型为 A 的表格流作为管道输入
  • 返回未修改类型的表的输入流
(<-tables: stream[A]) => stream[A]

基本转换

以下类型签名描述了一个 转换,它:

  • 接受类型为 A 的表流作为前置输入
  • 具有一个 fn 参数,其类型为函数
    • fn 使用类型 A 作为输入并返回类型 B
  • 返回一个新的、修改过的类型为 B 的表流
(<-tables: stream[A], fn: (r: A) => B,) => stream[B]

添加具有显式类型的列的转换

以下类型签名描述了一种 转换,它:

  • 接受类型为 A 的表流作为管道输入
  • 具有一个必需的 tag 参数,类型为 B
    • B 类型受限于 Stringable 约束
  • 返回一个新的、修改过的类型为 A 的表流,其中包含一个 tag 列,值为字符串
(<-tables: stream[A], tag: B) => stream[{A with tag: string}] where B: Stringable


Flux的未来

Flux 正在进入维护模式。您可以像现在一样继续使用它,而无需对您的代码进行任何更改。

阅读更多

InfluxDB 3 开源版本现已公开Alpha测试

InfluxDB 3 Open Source is now available for alpha testing, licensed under MIT or Apache 2 licensing.

我们将发布两个产品作为测试版的一部分。

InfluxDB 3 核心,是我们新的开源产品。 它是一个用于时间序列和事件数据的实时数据引擎。 InfluxDB 3 企业版是建立在核心基础之上的商业版本,增加了历史查询能力、读取副本、高可用性、可扩展性和细粒度安全性。

有关如何开始的更多信息,请查看: