ToStruct / Array Layer
Convert fixed-length arrays to structs where field names are automatically generated as 'field_0', 'field_1', etc. Similar to Polars' arr.to_struct().
Example transformation (arrays of length 3):
arrays | structs |
---|---|
[1, 2, 3] | {field_0: 1, field_1: 2, field_2: 3} |
[x, y, z] | {field_0: x, field_1: y, field_2: z} |
[true, false, null] | {field_0: true, field_1: false, field_2: null} |
[4, null, 6] | {field_0: 4, field_1: null, field_2: 6} |
Common applications:
- Converting arrays to named fields
- Creating structured data
- Making array elements accessible by field names
- Preparing data for structured analysis
Note: Field names follow the pattern 'field_N' where N is the zero-based index. Input arrays must have the same fixed length across all rows. Preserves null values.
Table
0
0
Table
Select
columnThe fixed-length array column to convert. Supports arrays of any type:
- Numeric arrays: [1, 2, 3] → {field_0: 1, field_1: 2, field_2: 3}
- String arrays: [x, y, z] → {field_0: x, field_1: y, field_2: z}
- Boolean arrays: [true, false, true] → {field_0: true, field_1: false, field_2: true}
- Date/time arrays: [2024-01-01, 2024-01-02, 2024-01-03] → {field_0: 2024-01-01, ...} All arrays must have the same length
AsColumn
nameName 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.