Skip to main content

FLATTEN

Written by Tom Williams

Type: Function

Function: FLATTEN

Syntax: FLATTEN(array_field)

Description: Flatten an array field (e.g. labels) to produce one parent record per value in the array. This operator is useful to turn arrays into single values. Aggregation logic can then be applied on those individual values (e.g. COUNT per individual label).

This operator can only be used in dimension formulas, it cannot be used in metric formulas.

In a filter, FLATTEN does nothing: it returns the array unchanged, so a dimension's formula can be reused in a filter as is. In a filter, CONTAINS(FLATTEN(label_names), "bug") is equivalent to CONTAINS(label_names, "bug"): both keep the records that have the label bug.

Sample usage:

  • FLATTEN(label_names) will produce one parent record per label in the label_names array, with each record having a single label.

  • FLATTEN(assignee_usernames) will produce one parent record per user in the assignee_usernames array, with each record having a single assignee.

  • Using FLATTEN(label_names) as dimension and COUNT() as metric will produce a reporting counting the number of time each label has been used across all records.

  • Using FLATTEN(label_names) as dimension 1, FLATTEN(assignee_usernames) as dimension 2 and COUNT() as metric will produce a reporting counting the number of label+assignee pairs.

  • Using FLATTEN(label_names) as dimension 1, LEFT(DIMENSION(1), 3) as dimension 2 gives the first three letters of each label, next to the label, without writing the FLATTEN twice. See DIMENSION.

Did this answer your question?