I am generating a query string dynamically as follows and passing it to selectExpr().
queryString=''''category_id as cat_id','category_department_id as cat_dpt_id','category_name as cat_name''''
df.selectExpr(queryString)
As per document
selectExpr(*expr) : Projects a set of SQL expressions and returns a new DataFrame. This is a variant of select() that accepts SQL expressions.
The issue is that the variable "queryString" is being treated as a single string instead of three separate columns ( and rightly so ). Following is the error:
: org.apache.spark.sql.catalyst.parser.ParseException: .........
== SQL ==
'category_id as cat_id', 'category_department_id as cat_dpt_id', 'category_name as cat_name'
------------------------^^^
Is there any way I can pass the dynamically generated "queryString" as an argument of selectExpr().