Documentation

rows.map() function

The rows.map() function is a user-contributed function maintained by the package author and can be updated or removed at any time.

The rows.map() function is an alternate implementation of map() that is faster, but more limited than map(). rows.map() cannot modify groups keys and, therefore, does not need to regroup tables. Attempts to change columns in the group key are ignored.

Function type: Transformation

import "contrib/jsternberg/rows"

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

Parameters

fn

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

Data type: Function

Use the with operator to preserve columns not in the group and not explicitly mapped in the operation.

Examples


Perform mathemtical operations on column values

The following example returns the square of each value in the _value column:

import "contrib/jsternberg/rows"

data
  |> rows.map(fn: (r) ({ _value: r._value * r._value }))

Important notes

The _time column is dropped because:

  • It’s not in the group key.
  • It’s not explicitly mapped in the operation.
  • The with operator was not used to include existing columns.

Input tables

Group key: tag,_field

tag_field_time_value
tag1foo00011.9
tag1foo00022.4
tag1foo00032.1
tag_field_time_value
tag2bar00013.1
tag2bar00023.8
tag2bar00031.7

Output tables

Group key: tag,_field

tag_field_value
tag1foo3.61
tag1foo5.76
tag1foo4.41
tag_field_value
tag2bar9.61
tag2bar14.44
tag2bar2.89

Preserve all columns in the operation

Use the with operator in your mapping operation to preserve all columns, including those not in the group key, without explicitly remapping them.

import "contrib/jsternberg/rows"

data
  |> rows.map(fn: (r) ({ r with _value: r._value * r._value }))

Important notes

  • The mapping operation remaps the _value column.
  • The with operator preserves all other columns not in the group key (_time).

Input tables

Group key: tag,_field

tag_field_time_value
tag1foo00011.9
tag1foo00022.4
tag1foo00032.1
tag_field_time_value
tag2bar00013.1
tag2bar00023.8
tag2bar00031.7

Output tables

Group key: tag,_field

tag_field_time_value
tag1foo00013.61
tag1foo00025.76
tag1foo00034.41
tag_field_time_value
tag2bar00019.61
tag2bar000214.44
tag2bar00032.89

Attempt to remap columns in the group key

import "contrib/jsternberg/rows"

data
  |> rows.map(fn: (r) ({ r with tag: "tag3" }))

Important notes

  • Remapping the tag column to "tag3" is ignored because tag is part of the group key.
  • The with operator preserves columns not in the group key (_time and _value).

Input tables

Group key: tag,_field

tag_field_time_value
tag1foo00011.9
tag1foo00022.4
tag1foo00032.1
tag_field_time_value
tag2bar00013.1
tag2bar00023.8
tag2bar00031.7

Output tables

Group key: tag,_field

tag_field_time_value
tag1foo00011.9
tag1foo00022.4
tag1foo00032.1
tag_field_time_value
tag2bar00013.1
tag2bar00023.8
tag2bar00031.7

Package author and maintainer

Github: @jsternberg
InfluxDB Slack: @Jonathan Sternberg


New! Cloud or OSS?