docs-v2/content/v2.0/reference/flux/functions/built-in/transformations/keep.md

1.6 KiB

title description aliases menu weight
keep() function The `keep()` function returns a table containing only the specified columns.
/v2.0/reference/flux/functions/transformations/keep
v2_0_ref
name parent
keep built-in-transformations
401

The keep() function returns a table containing only the specified columns, ignoring all others. Only columns in the group key that are also specified in the keep() function will be kept in the resulting group key. It is the inverse of drop.

Function type: Transformation
Output data type: Object

keep(columns: ["col1", "col2"])

// OR

keep(fn: (column) => column =~ /inodes*/)

Parameters

{{% note %}} Make sure fn parameter names match each specified parameter. To learn why, see Match parameter names. {{% /note %}}

columns

Columns that should be included in the resulting table. Cannot be used with fn.

Data type: Array of strings

fn

A predicate function which takes a column name as a parameter (column) and returns a boolean indicating whether or not the column should be included in the resulting table. Cannot be used with columns.

Data type: Function

Examples

Keep a list of columns
from(bucket: "example-bucket")
    |> range(start: -5m)
    |> keep(columns: ["_time", "_value"])
Keep all columns matching a predicate
from(bucket: "example-bucket")
    |> range(start: -5m)
    |> keep(fn: (column) => column =~ /inodes*/)