Имеется фрейм данных со списком массивов
Schema
|-- items: array (nullable = true)
| |-- element: struct (containsNull = true)
| | |-- name: string (nullable = true)
| | |-- quantity: string (nullable = true)
+-------------------------------+
|items |
+-------------------------------+
|[[A, 1], [B, 1], [C, 2]] |
---------------------------------
Как получить строку:
+-------------------------------+
|items |
+-------------------------------+
|A, 1, B, 1, C, 2 |
---------------------------------
Пробовал:
df.withColumn('item_str', concat_ws(" ", col("items"))).select("item_str").show(truncate = False)
Ошибка:
: org.apache.spark.sql.AnalysisException: cannot resolve 'concat_ws(' ', `items`)' due to data type mismatch: argument 2 requires (array<string> or string) type, however, '`items`' is of array<struct<name:string,quantity:string>> type.;;