I have two tables with columns table1 has id,name and table2 has only id
table 1
--------------
id name
--------------
1 sudheer
2 sandeep
3 suresh
----------------
table2
--------
id
--------
1
2
-------
required table should be if "id" column doesn't exist in the table2 my new column value should be "N" otherwise "Y"
table3
id name IND
1 sudheer Y
2 sandeep Y
3 suresh N
I have tried the below steps to approach:
val df = hc.sql("select * from table1")
val df1 = hc.sql("select * from table2")
I tried to have a one more column (phone) in table2,as my join dataframe doesn't consist of id from table2,based on that null value I tried to set the value to Y/N
val df2 = df.join(df1,Seq("id"),"left_outer").withColumn("IND",exp(when(df1("phone")!= "null","Y").otherwise("N")))
But this didn't worked out with error found : Boolean required: org.apache.spark.sql.Column
Can anyone suggest any idea how to get the required result without adding a column to my table2?
withColumn("IND", when(col("phone").isNotNull, "Y").otherwise("N")).