Need to perform some queries to a table inside of a UDF in structured streaming. The problem is, inside the UDF if i try to use spark.sql, i am getting null pointer exception. What is the best way to follow here.
Basically i need to stream from a table, and then use that data to perform some range queries from another table.
Eg.
val appleFilter = udf((appleId : String) => {
val query = "select count(*) from appleMart where appleId='"+appleId+"'"
val appleCount = spark.sql(query).collect().head.getLong(0)
(appleCount>0)
})
val newApple = apples.filter(appleFilter($"appleId"))