experimental.to() function

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

The experimental.to() function writes data to an InfluxDB v2.0 bucket, but in a different structure than the built-in to() function.

*Function type: Output*

  1. import "experimental"
  2. experimental.to(
  3. bucket: "my-bucket",
  4. org: "my-org"
  5. )
  6. // OR
  7. experimental.to(
  8. bucketID: "1234567890",
  9. orgID: "0987654321"
  10. )

Expected data structure

Data structure expected by built-in to()

The built-in to() function requires _time, _measurement, _field, and _value columns. The _field column stores the field key and the _value column stores the field value.

_time_measurement_field_value
timestampmeasurement-namefield keyfield value

Data structure expected by experimental to()

experimental.to() requires _time and measurement columns, but field keys and values are stored in single columns with the field key as the column name and the field value as the column value.

_time_measurementfield_key
timestampmeasurement-namefield value

If using the built-in from() function, use pivot() to transform data into the structure experimetnal.to() expects. See the example below.

Parameters

bucket

The bucket to write data to. bucket and bucketID are mutually exclusive.

*Data type: String*

bucketID

The ID of the bucket to write data to. bucketID and bucket are mutually exclusive.

*Data type: String*

org

The organization name of the specified bucket. Only required when writing to a different organization or a remote host. org and orgID are mutually exclusive.

*Data type: String*

orgID

The organization ID of the specified bucket. Only required when writing to a different organization or a remote host. orgID and org are mutually exclusive.

*Data type: String*

Examples

Use pivot() to shape data for experimental.to()
  1. import "experimental"
  2. from(bucket: "example-bucket")
  3. |> range(start: -1h)
  4. |> pivot(
  5. rowKey:["_time"],
  6. columnKey: ["_field"],
  7. valueColumn: "_value")
  8. |> experimental.to(
  9. bucket: "bucket-name",
  10. org: "org-name"
  11. )

Related articles