map() function

The map() function applies a function to each record in the input tables. The modified records are assigned to new tables based on the group key of the input table. The output tables are the result of applying the map function to each record of the input tables.

When the output record contains a different value for the group key, the record is regrouped into the appropriate table. When the output record drops a column that was part of the group key, that column is removed from the group key.

map(fn: (r) => ({ _value: r._value * r._value }))


Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names.


A single argument function to apply to each record. The return value must be a record.

Records evaluated in fn functions are represented by r, short for “record” or “row”.


Input data. Default is piped-forward data (<-).

Important notes

Preserve columns

By default, map() drops any columns that:

  1. Are not part of the input table’s group key.
  2. Are not explicitly mapped in the map() function.

This often results in the _time column being dropped. To preserve the _time column and other columns that do not meet the criteria above, use the with operator to map values in the r record. The with operator updates a column if it already exists, creates a new column if it doesn’t exist, and includes all existing columns in the output table.

map(fn: (r) => ({ r with newColumn: r._value * 2 }))


The following examples use data provided by the sampledata package to show how map() transforms data.

Square the value in each row

import "sampledata"
  |> map(fn: (r) => ({ r with _value: r._value * r._value }))

View input and output

Create a new table with new columns

import "sampledata"
    |> map(
        fn: (r) => ({
            time: r._time,
            source: r.tag,
            alert: if r._value > 10 then true else false

View input and output

Add new columns and preserve existing columns

Use the with operator on the r record to preserve columns not directly operated on by the map operation.

import "sampledata"
  |> map(
      fn: (r) => ({
          r with
          server: "server-${r.tag}",
          valueFloat: float(v: r._value)

View input and output


Map object property is not supported in a Flux table

Flux tables only support the following value types:

  • float
  • integer
  • unsigned integer
  • string
  • boolean
  • time

If map() returns a record with an unsupported type, Flux returns an error with the name of the column that attempted to use the unsupported type.

If mapping a duration value, use time() to convert it to a time value or int() to convert it to an integer. For the bytes type, use string() to convert the value to a string.

For information about supporting other data types in Flux tables, see the following Github issues:

Was this page helpful?

Thank you for your feedback!

Upgrade to InfluxDB Cloud or InfluxDB 2.0!

InfluxDB Cloud and InfluxDB OSS 2.0 ready for production.