I have a big Dataframe with columns user_id, user_address and multiple user related columns (10-12 more) and a small (< 2MB) Dataframe with columns user_id and user_contact. Each user can have lots of phone numbers/email addresses.
I am trying to broadcast the smaller Dataframe and pass its data to an UDF. However, I am not able to get all the data present in each of the executors. As the UDF returns No match found if no contact details found for that user_id.
I try to filter the broadcastDF by the user_id, but seems like that is not working. Can someone please guide me here?
val DF = createDF("/somePath/")
val broadcastedDF = spark.sparkContext.broadcast(DF)
val DFWithUDF = someDF.select( col("user_id),
UDF(col("user_name"),
typedLit[Seq[String]](broadcastedDF.value.filter(broadcastedDF.value("user_id") === col("user_id")).
select("user_contact").
collect().map(data =>
String.valueOf(data.getAs[String]("user_contact")))
)
).alias(SCHEMA_REQUEST_TARGET)