I have an array of structs and I want to create a new column, but only select a few columns from the struct.
Currently, I am doing it this way:
F.array(F.struct(
F.col('orig_column.item_1'),
F.col('orig_column.item_2'),
F.col('orig_column.item_3')))
However, the schema is not what I want. I get this:
root
|-- orig_column: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- item_1: long (nullable = true)
| | |-- item_2: long (nullable = true)
| | |-- item_3: long (nullable = true)
| | |-- item_4: integer (nullable = true)
| | |-- item_5: integer (nullable = true)
| | |-- item_6: integer (nullable = true)
| | |-- item_7: boolean (nullable = true)
|-- new_column: array (nullable = false)
| |-- element: struct (containsNull = false)
| | |-- item_1: array (nullable = true)
| | | |-- element: long (containsNull = true)
| | |-- item_2: array (nullable = true)
| | | |-- element: long (containsNull = true)
| | |-- item_3: array (nullable = true)
| | | |-- element: long (containsNull = true)
| | |-- item_4: array (nullable = true)
| | | |-- element: integer (containsNull = true)
What I wanted to happen is:
root
|-- new_column: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- item_1: long (nullable = true)
| | |-- item_2: long (nullable = true)
| | |-- item_3: long (nullable = true)
What am I doing wrong?