rename() function

The rename() function renames specified columns in a table. If a column is renamed and is part of the group key, the column name in the group key will be updated.

There are two variants:

  • one which maps old column names to new column names
  • one which takes a mapping function.

*Function type: Transformation*

  1. rename(columns: {host: "server", facility: "datacenter"})
  2. // OR
  3. rename(fn: (column) => "{column}_new")

Parameters

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

columns

A map of columns to rename and their corresponding new names. Cannot be used with fn.

*Data type: Record*

fn

A function mapping between old and new column names. Cannot be used with columns.

*Data type: Function*

Examples

Rename a single column
  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> rename(columns: {host: "server"})
Rename all columns using a function
  1. from(bucket: "example-bucket")
  2. |> range(start: -5m)
  3. |> rename(fn: (column) => column + "_new")