fill() function

The fill() function replaces all null values in an input stream with a non-null value. The output stream is the same as the input stream with all null values replaced in the specified column.

*Function type: Transformation*

  1. fill(column: "_value", value: 0.0)
  2. // OR
  3. fill(column: "_value", usePrevious: true)

Parameters

column

The column in which to replace null values. Defaults to "_value".

*Data type: String*

value

The constant value to use in place of nulls. The value type must match the value type of the column.

*Data type: Boolean | Integer | UInteger | Float | String | Time | Duration*

usePrevious

When true, assigns the value set in the previous non-null row.

Cannot be used with value.

*Data type: Boolean*

Examples

Fill null values with a specified non-null value
  1. from(bucket: "example-bucket")
  2. |> range(start: -1h)
  3. |> filter(fn: (r) =>
  4. r._measurement == "cpu" and
  5. r.cpu == "cpu-total"
  6. )
  7. |> fill(value: 0.0)
Fill null values with the previous non-null value
  1. from(bucket: "example-bucket")
  2. |> range(start: -1h)
  3. |> filter(fn: (r) =>
  4. r._measurement == "cpu" and
  5. r.cpu == "cpu-total"
  6. )
  7. |> fill(usePrevious: true)

Related articles