I am using the following data:
Data for df1:
c1,c2,c3,c4
k1,i,aa,k
k5,j,ee,l
Data for df2:
c1,avc2,c3,avc4
k1,a,aa,e
k2,b,bb,f
k3,c,cc,g
k4,d,dd,h
I am trying to create a dynamic query string based on the conditions using the code below:
val PRIM_CHECK="c1,c3".split(",").toList
val COLUMN_UNCHANGE="c4".split(",").toList
var qb = new ListBuffer[String]()
val df3=df1.join(df2,seq("c1","c3"), "outer")
for(i<-avro_inp.columns)
{
if(PRIM_CHECK.contains(i))
{
}
else if(COLUMN_UNCHANGE.contains(i))
{
qb+=""".withColumn(""""+i+"""", when('"""+""+i+""".isNotNull,'"""+i+""").otherwise('av"""+""+i+"""))"""
}
else
{
qb+=""".withColumn(""""+i+"""", when('av"""+""+i+""".isNull,'"""+i+""").otherwise('av"""+""+i+"""))"""
}
}
val check=qb.mkString
However, I want to run the below code
df3.+""+check+""+.show()
But, I could not run the above code because of the string in the query. Is there any way that I can execute it?