Documentation

join() function

Flux 0.7.0+

The join() function merges two input streams 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.

join(
  tables: {key1: table1, key2: table2},
  on: ["_time", "_field"],
  method: "inner"
)

Output schema

The column schema of the output stream is the union of the input schemas. It is also the same for the output group key. Columns are renamed using the pattern <column>_<table> to prevent ambiguity in joined tables.

Example:

If you have two streams of data, data_1 and data_2, with the following group keys:

data_1: [_time, _field]
data_2: [_time, _field]

And join them with:

join(tables: {d1: data_1, d2: data_2}, on: ["_time"])

The resulting group keys for all tables will be: [_time, _field_d1, _field_d2]

Parameters

tables

(Required) Map of two streams to join.

join() currently only supports two input streams.

on

(Required) List of columns to join on.

method

Join method to use to join. Default is "inner".

Possible Values:
  • inner

Examples

The following example uses generate.from() to illustrate how join() transforms data.

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

Input data streams

t1
_timetag_value
2021-01-01T00:00:00Zfoo1
2021-01-02T00:00:00Zfoo2
2021-01-03T00:00:00Zfoo3
2021-01-04T00:00:00Zfoo4
t2
_timetag_value
2021-01-01T00:00:00Zfoo0
2021-01-02T00:00:00Zfoo-1
2021-01-03T00:00:00Zfoo-2
2021-01-04T00:00:00Zfoo-3

Output data stream

_timetag_value_t1_value_t2
2021-01-01T00:00:00Zfoo10
2021-01-02T00:00:00Zfoo2-1
2021-01-03T00:00:00Zfoo3-2
2021-01-04T00:00:00Zfoo4-3

InfluxDB cross-measurement join

The following example shows how data in different InfluxDB measurements can be joined with Flux.

data_1 = from(bucket:"example-bucket")
  |> range(start:-15m)
  |> filter(fn: (r) =>
    r._measurement == "cpu" and
    r._field == "usage_system"
  )

data_2 = from(bucket:"example-bucket")
  |> range(start:-15m)
  |> filter(fn: (r) =>
    r._measurement == "mem" and
    r._field == "used_percent"
  )

join(
  tables: {d1: data_1, d2: data_2},
  on: ["_time", "host"]
)

join() versus 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 unifies separate streams of tables into a single stream of tables and groups rows of data based on existing group keys.

View join() vs union() example


Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.