Documentation

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"])

Was this page helpful?

Thank you for your feedback!


Introducing InfluxDB Clustered

A highly available InfluxDB 3.0 cluster on your own infrastructure.

InfluxDB Clustered is a highly available InfluxDB 3.0 cluster built for high write and query workloads on your own infrastructure.

InfluxDB Clustered is currently in limited availability and is only available to a limited group of InfluxData customers. If interested in being part of the limited access group, please contact the InfluxData Sales team.

Learn more
Contact InfluxData Sales

The future of Flux

Flux is going into maintenance mode. You can continue using it as you currently are without any changes to your code.

Flux is going into maintenance mode and will not be supported in InfluxDB 3.0. This was a decision based on the broad demand for SQL and the continued growth and adoption of InfluxQL. We are continuing to support Flux for users in 1.x and 2.x so you can continue using it with no changes to your code. If you are interested in transitioning to InfluxDB 3.0 and want to future-proof your code, we suggest using InfluxQL.

For information about the future of Flux, see the following:

State of the InfluxDB Cloud Serverless documentation

InfluxDB Cloud Serverless documentation is a work in progress.

The new documentation for InfluxDB Cloud Serverless is a work in progress. We are adding new information and content almost daily. Thank you for your patience!

If there is specific information you’re looking for, please submit a documentation issue.