I am trying to rename the columns of a data frame based on another dataframe. How can i achieve this using Scala?
Essentially my data looks like
DataFrame1
A B C D
1 2 3 4
I have another table that looks like this DataFrame2
Col1 Col2
A E
B Q
C R
D Z
I want to rename the columns of my first data frame with respect to other dataframe. so that expected output should look like this:
E Q R Z
1 2 3 4
I have tried the code using PySpark (copied from this answer by user8371915) and this is working fine:
name_dict = dataframe2.rdd.collectAsMap()
dataframe1.select([dataframe[c].alias(name_dict.get(c, c)) for c in dataframe1.columns]).show()
Now, how can i achieve this using Scala?