docs-v2/content/v2.0/reference/flux/stdlib/built-in/transformations/union.md

2.0 KiB

title description aliases menu weight related
union() function The `union()` function concatenates two or more input streams into a single output stream.
/v2.0/reference/flux/functions/transformations/union
/v2.0/reference/flux/functions/built-in/transformations/union/
v2_0_ref
name parent
union built-in-transformations
402
/v2.0/reference/flux/stdlib/built-in/transformations/join/

The union() function concatenates two or more input streams into a single output stream. In tables that have identical schemas and group keys, contents of the tables will be concatenated in the output stream. The output schemas of the union() function is the union of all input schemas.

union() does not preserve the sort order of the rows within tables. A sort operation may be added if a specific sort order is needed.

Function type: Transformation
Output data type: Object

union(tables: [table1, table2])

Parameters

tables

Specifies the streams to union together. There must be at least two streams.

Data type: Array of streams

Examples

bucket1 = from(bucket: "example-bucket-1")
  |> range(start: -5m)
  |> filter(fn: (r) => r._field == "usage_guest" or r._field == "usage_guest_nice")

bucket2 = from(bucket: "example-bucket-2")
  |> range(start: -5m)
  |> filter(fn: (r) => r._field == "usage_guest" or r._field == "usage_idle")

union(tables: [bucket1, bucket2])

union() versus join()

union() merges separate streams of tables into a single stream of tables and groups rows of data based on existing group keys. union() does not modify individual rows of data. 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.

Given two streams of tables, t1 and t2, the results of join() and union() are illustrated below:

{{< svg "/static/svgs/join-vs-union.svg" >}}