'How to pass a list to .agg in scala?

I have to do this command:

df.groupBy('docid', 'vehicle_vin').pivot('intervaltype').agg(first('NAME_COLUMN1').alias('NAME_COLUMN1'))

And i want to pass dynamically the name of the column that are saved in a list:

(NAME_COLUMN1,NAME_COLUMN2,NAME_COLUMN3.....)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source