I am trying to pass a variable SCD_filter to the where clause in the dataframe in spark for which I am receiving an error but when passed directly its working fine.I am doing this to dynamically pass this filter based on different scenarios for future use.
val SCD_filter = """currentDF.col("u_business_unit") <=> updatedDF.col("u_business_unit")
| and(currentDF.col("u_operation_level_2") <=> updatedDF.col("u_operation_level_2"))
| and(currentDF.col("u_operation_level_3") <=> updatedDF.col("u_operation_level_3"))""".stripMargin
I am then passing the variable to the code below:
val common_unchangedata = currentDF.alias("currentDF")
.join(updatedDF, currentDF.col("Sys_id") === updatedDF.col("Sys_id"), "inner")
.select("currentDF.*")
.where(s"$SCD_filter") /// passing the variable which is causing the error
.show()
Error Received:
Exception in thread "main" org.apache.spark.sql.catalyst.analysis.NoSuchDatabaseException: Database 'currentdf' not found;
Note: the currentDF is fine as the code is executing when variable is removed and we pass the condition to the where clause instaed of variable.enter image description here