How does the code below concatenate multiple values in the list?
concat(myList.map(fld => col(fld)): _*)
How does the code below concatenate multiple values in the list?
concat(myList.map(fld => col(fld)): _*)
According to Spark documentation the signature of the concat function is concat(col1, col2, ..., colN)
. Given your list contains the column names, i.e: c1, c2 ... cN
, map
will convert each one of these into Column class objects. The conversion is done using the col function. Finally, the _*
will unpack the (converted to Column) list items, similarly to how python's * operator works, assigning concat
arguments.