Reputation: 363
I have a map defined with key value pair. While selecting column I for a dataframe I need to dynamically fetch column name as value from Map based on key provided like,
val map = HashMap("emp_id" -> "dept_id","emp_city" -> "dept_city" );
val df1 = df.select($"$map.get($name)")
Here name
will be key in map and I need to get related value in expression above but it throws error. What could be problem here
Upvotes: 0
Views: 957
Reputation: 363
As suggested by Tzach, the problem was with string interpolation- changing the expression to $"df.${map.get(name).mkString}"
fixed the issue
Upvotes: 0