I'm executing a query on RDBMS and getting the result as a String. The String looks something like this:
val DBASE = "my_database"
val FREQ = "monthly"
val queryResult: String = sqlContext.read.jdbc(...).collect.map(...).first
// queryResult = Database is $$${DBASE} and frequency is $$${FREQ}
Next I'm replacing $$$ with $, so I'm left with something like:
queryResult = "Database is ${DBASE} and frequency is ${FREQ}"
How to use String Interpolation on DBASE and FREQ? I have tried:
val substituted = f"${queryResult}"
and
val substituted = s"${queryResult}"
But the variables are not getting replaced. Is there something else I can do apart from using the following :
queryResult.replaceAll("\\$\\{DBASE\\}", DBASE).replaceAll(...)