文档文档

join() function

join() merges two streams of tables into a single output stream based on columns with equal values. Null values are not considered equal when comparing column values. The resulting schema is the union of the input schemas. The resulting group key is the union of the input group keys.

Deprecated

join() is deprecated in favor of join.inner(). The join package provides support for multiple join methods.

Output data

The schema and group keys of the joined output output data is the union of the input schemas and group keys. Columns that exist in both input streams that are not part specified as columns to join on are renamed using the pattern <column>_<table> to prevent ambiguity in joined tables.

Join vs union

join() creates new rows based on common values in one or more specified columns. Output rows also contain the differing values from each of the joined streams. union() does not modify data in rows, but unions separate streams of tables into a single stream of tables and groups rows of data based on existing group keys.

Function type signature
(<-tables: A, ?method: string, ?on: [string]) => stream[B] where A: Record, B: Record

For more information, see Function type signatures.

Parameters

tables

Record containing two input streams to join.

on

List of columns to join on.

method

Join method. Default is inner.

Supported methods:

  • inner

Examples

Join two streams of tables

import "generate"

t1 =
    generate.from(
        count: 4,
        fn: (n) => n + 1,
        start: 2021-01-01T00:00:00Z,
        stop: 2021-01-05T00:00:00Z,
    )
        |> set(key: "tag", value: "foo")

t2 =
    generate.from(
        count: 4,
        fn: (n) => n * (-1),
        start: 2021-01-01T00:00:00Z,
        stop: 2021-01-05T00:00:00Z,
    )
        |> set(key: "tag", value: "foo")

join(tables: {t1: t1, t2: t2}, on: ["_time", "tag"])

View example output

Join data from separate data sources

import "sql"

sqlData =
    sql.from(
        driverName: "postgres",
        dataSourceName: "postgresql://username:password@localhost:5432",
        query: "SELECT * FROM example_table",
    )

tsData =
    from(bucket: "example-bucket")
        |> range(start: -1h)
        |> filter(fn: (r) => r._measurement == "example-measurement")
        |> filter(fn: (r) => exists r.sensorID)

join(tables: {sql: sqlData, ts: tsData}, on: ["_time", "sensorID"])

此页是否对您有帮助?

感谢您的反馈!


Flux 的未来

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

阅读更多

InfluxDB 3 开源版本现已推出公共 Alpha 版

InfluxDB 3 开源版本现在可用于 alpha 测试,并根据 MIT 或 Apache 2 许可进行许可。

我们将发布两款产品作为 alpha 版本的一部分。

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

有关如何入门的更多信息,请查看