ToStruct / List Layer

Convert variable-length lists to structs with automatically generated field names 'field_0', 'field_1', etc. Similar to Polars' arr.to_struct(). Preserves all list elements regardless of length.

Example transformation:

listsstructs
[1, 2, 3, 4]{field_0: 1, field_1: 2, field_2: 3, field_3: 4}
[x, y]{field_0: x, field_1: y}
[true]{field_0: true}
[]{}
[1, null, 3]{field_0: 1, field_1: null, field_2: 3}

Common applications:

  • Converting dynamic lists to named fields
  • Creating flexible structured data
  • Enabling field-based access to list elements
  • Preparing data for columnar analysis
  • Transforming lists for structured queries
  • Creating self-describing data structures

Note: Field names follow pattern 'field_N' where N is zero-based index. Empty lists create empty structs. Preserves null values. Particularly useful for converting variable-length sequences to named field access.

Table
0
0
Table

Select

column

The variable-length list column to convert. Examples:

  • Numeric lists: [1, 2, 3] → {field_0: 1, field_1: 2, field_2: 3}
  • String lists: [x, y] → {field_0: x, field_1: y}
  • Mixed lengths: [true], [a, b, c] → {field_0: true}, {field_0: a, field_1: b, ...} Lists can have different lengths. Any type supported.

Name for the new column. If not provided, the system generates a unique name. If AsColumn matches an existing column, the existing column is replaced. The name should follow valid column naming conventions.