Documentation

union() function

union() merges two or more input streams into a single output stream.

The output schemas of union() is the union of all input schemas. union() does not preserve the sort order of the rows within tables. Use sort() if you need a specific sort order.

Union vs join

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. 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.

Function type signature
(tables: [stream[A]]) => stream[A] where A: Record

For more information, see Function type signatures.

Parameters

tables

(Required) List of two or more streams of tables to union together.

Examples

Union two streams of tables with unique group keys

import "generate"

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

t2 =
    generate.from(
        count: 4,
        fn: (n) => n * (-1),
        start: 2022-01-01T00:00:00Z,
        stop: 2022-01-05T00:00:00Z,
    )
        |> set(key: "tag", value: "bar")
        |> group(columns: ["tag"])

union(tables: [t1, t2])

View example output

Union two streams of tables with empty group keys

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")
        |> group()

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: "bar")
        |> group()

union(tables: [t1, t2])

View example output


Was this page helpful?

Thank you for your feedback!


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.

Read more

InfluxDB v3 enhancements and InfluxDB Clustered is now generally available

New capabilities, including faster query performance and management tooling advance the InfluxDB v3 product line. InfluxDB Clustered is now generally available.

InfluxDB v3 performance and features

The InfluxDB v3 product line has seen significant enhancements in query performance and has made new management tooling available. These enhancements include an operational dashboard to monitor the health of your InfluxDB cluster, single sign-on (SSO) support in InfluxDB Cloud Dedicated, and new management APIs for tokens and databases.

Learn about the new v3 enhancements


InfluxDB Clustered general availability

InfluxDB Clustered is now generally available and gives you the power of InfluxDB v3 in your self-managed stack.

Talk to us about InfluxDB Clustered