experimental.join() function

The experimental.join() function is subject to change at any time. By using this function, you accept the risks of experimental functions.

The experimental.join() function joins two streams of tables on the group key and _time column. Use the fn parameter to map new output tables using values from input tables.

To join streams of tables with different fields or measurements, use group() or drop() to remove _field and _measurement from the group key before joining. See an example below.

*Function type: Transformation*

  1. import "experimental"
  2. // ...
  3. experimental.join(
  4. left: left,
  5. right: right,
  6. fn: (left, right) => ({left with lv: left._value, rv: right._value })
  7. )

This function will likely replace the join function when sufficiently vetted.

Parameters

left

First of two streams of tables to join.

*Data type: Stream of tables*

right

Second of two streams of tables to join.

*Data type: Stream of tables*

fn

A function with left and right arguments that maps a new output record using values from the left and right input records. The return value must be a record.

*Data type: Function*

Examples

Input and output tables

Given the following input tables:

left
_time_field_value
0001temp80.1
0002temp80.2
0003temp79.9
0004temp80.0
right
_time_field_value
0001temp72.1
0002temp72.2
0003temp71.9
0004temp72.0

The following experimental.join() function would output:

  1. import "experimental"
  2. experimental.join(
  3. left: left,
  4. right: right,
  5. fn: (left, right) => ({
  6. left with
  7. lv: left._value,
  8. rv: right._value,
  9. diff: left._value - right._value
  10. })
  11. )
_time_fieldlvrvdiff
0001temp80.172.18.0
0002temp80.272.28.0
0003temp79.971.98.0
0004temp80.072.08.0

Join two streams of tables
  1. import "experimental"
  2. s1 = from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> filter(fn: (r) => r._measurement == "foo")
  5. s2 = from(bucket: "example-bucket")
  6. |> range(start: -1h)
  7. |> filter(fn: (r) => r._measurement == "bar")
  8. experimental.join(
  9. left: s1,
  10. right: s2,
  11. fn: (left, right) => ({
  12. left with
  13. s1_value: left._value,
  14. s2_value: right._value
  15. })
  16. )
Join two streams of tables with different fields and measurements
  1. import "experimental"
  2. s1 = from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> filter(fn: (r) => r._measurement == "foo" and r._field == "bar")
  5. |> group(columns: ["_time", "_measurement", "_field", "_value"], mode: "except")
  6. s2 = from(bucket: "example-bucket")
  7. |> range(start: -1h)
  8. |> filter(fn: (r) => r._measurement == "baz" and r._field == "quz")
  9. |> group(columns: ["_time", "_measurement", "_field", "_value"], mode: "except")
  10. experimental.join(
  11. left: s1,
  12. right: s2,
  13. fn: (left, right) => ({
  14. left with
  15. bar_value: left._value,
  16. quz_value: right._value
  17. })
  18. )