Back to Influxdb

drop() function

content/flux/v0/stdlib/universe/drop.md

latest4.2 KB
Original Source
<!------------------------------------------------------------------------------ IMPORTANT: This page was generated from comments in the Flux source code. Any edits made directly to this page will be overwritten the next time the documentation is generated. To make updates to this documentation, update the function comments above the function definition in the Flux source code: https://github.com/influxdata/flux/blob/master/stdlib/universe/universe.flux#L462-L465 Contributing to Flux: https://github.com/influxdata/flux#contributing Fluxdoc syntax: https://github.com/influxdata/flux/blob/master/docs/fluxdoc.md ------------------------------------------------------------------------------->

drop() removes specified columns from a table.

Columns are specified either through a list or a predicate function. When a dropped column is part of the group key, it is removed from the key. If a specified column is not present in a table, the function returns an error.

Function type signature
js
(<-tables: stream[A], ?columns: [string], ?fn: (column: string) => bool) => stream[B] where A: Record, B: Record

{{% caption %}} For more information, see Function type signatures. {{% /caption %}}

Parameters

columns

List of columns to remove from input tables. Mutually exclusive with fn.

fn

Predicate function with a column parameter that returns a boolean value indicating whether or not the column should be removed from input tables. Mutually exclusive with columns.

tables

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

Examples

Drop a list of columns

js
import "sampledata"

sampledata.int()
    |> drop(columns: ["_time", "tag"])

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag
2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:10Z10t1
2021-01-01T00:00:20Z7t1
2021-01-01T00:00:30Z17t1
2021-01-01T00:00:40Z15t1
2021-01-01T00:00:50Z4t1
_time_value*tag
2021-01-01T00:00:00Z19t2
2021-01-01T00:00:10Z4t2
2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:30Z19t2
2021-01-01T00:00:40Z13t2
2021-01-01T00:00:50Z1t2

Output data

_value
-2
10
7
17
15
4
19
4
-3
19
13
1

{{% /expand %}} {{< /expand-wrapper >}}

Drop columns matching a predicate

js
import "sampledata"

sampledata.int()
    |> drop(fn: (column) => column =~ /^t/)

{{< expand-wrapper >}} {{% expand "View example input and output" %}}

Input data

_time_value*tag
2021-01-01T00:00:00Z-2t1
2021-01-01T00:00:10Z10t1
2021-01-01T00:00:20Z7t1
2021-01-01T00:00:30Z17t1
2021-01-01T00:00:40Z15t1
2021-01-01T00:00:50Z4t1
_time_value*tag
2021-01-01T00:00:00Z19t2
2021-01-01T00:00:10Z4t2
2021-01-01T00:00:20Z-3t2
2021-01-01T00:00:30Z19t2
2021-01-01T00:00:40Z13t2
2021-01-01T00:00:50Z1t2

Output data

_time_value
2021-01-01T00:00:00Z-2
2021-01-01T00:00:10Z10
2021-01-01T00:00:20Z7
2021-01-01T00:00:30Z17
2021-01-01T00:00:40Z15
2021-01-01T00:00:50Z4
2021-01-01T00:00:00Z19
2021-01-01T00:00:10Z4
2021-01-01T00:00:20Z-3
2021-01-01T00:00:30Z19
2021-01-01T00:00:40Z13
2021-01-01T00:00:50Z1

{{% /expand %}} {{< /expand-wrapper >}}