How can I create column colMap of ArrayType[StringType] which value is Array with elements being strings matching names of the column which values were true?
I have such input DataFrame:
+-----+-----+-----+
|col1 |col2 |col3 |
+-----+-----+-----+
|true |false|true |
|false|false|false|
|false|false|true |
+-----+-----+-----+
and I want to create such output DataFrame:
+-----+-----+-----+------------+
|col1 |col2 |col3 |colMap |
+-----+-----+-----+------------+
|true |false|true |[col1, col3]|
|false|false|false|[] |
|false|false|true |[col3] |
+-----+-----+-----+------------+
EDIT: I have found this duplicated question:
Spark scala get an array of type string from multiple columns
but wonder if there is better way to achieve the output?