Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from space DEV and version r0811

D toc

D s transforms

Excerpt

Unpacks array data into separate rows for each value. This transform operates on a single column.

This transform does not reference keys in the array. If your array data contains keys, use the unnest transform. See Unnest Transform.

D s
snippetBasic

D code

flatten col: myArray

Output: Generates a separate row for each value in the array. Values of other columns in generated rows are copied from the source. 

D s
snippetParameters

D code

flatten: col: column_ref

TokenRequired?Data TypeDescription
flattenYtransformName of the transform
colYstringSource column name 

D s lang notes

col

Identifies the column to which to apply the transform. You can specify only one column.

D s
snippetusage

Required?Data Type
YesString (column name)


D s
snippetExamples

Example - Flatten an array

Include Page
EXAMPLE - Flatten an Array
EXAMPLE - Flatten an Array

Example - Flatten and unnest together

While the above example nicely flattens out your data, there are two potential problems with the results:

  • There is no identifier for each test. For example, Allen Adams' score of 87 cannot be associated with the specific test on which he recorded the score.
  • There is no unique identifier for each row.

The following example addresses both of these issues. It also demonstrates differences between the  unnest and the flatten transform, including how you use  unnest to flatten array data based on specified keys.

Include Page
EXAMPLE - Flatten and Unnest Transforms
EXAMPLE - Flatten and Unnest Transforms

D s also
labelwrangle_transform_flatten