Spark Structured Streaming - Processing each row

Viewed 4131

I am using structured streaming with Spark 2.1.1. I need to apply some business logic to incoming messages (from Kafka source).

essentially, I need to pick up the message, get some key values, look them up in HBase and perform some more biz logic on the dataset. the end result is a string message that needs to be written out to another Kafka queue.

However, since the abstraction for incoming messages is a dataframe (unbounded table - structured streaming), I have to iterate through the dataset received during a trigger through mapPartitions (partitions due to HBase client not being serializable).

During my process, i need to iterate through each row for executing the business process for the same.

  1. Is there a better approach possible that could help me avoid the dataFrame.mapPartitions call? I feel its sequential and iterative !!
  2. Structured streaming basically forces me to generate an output data frame out of my business process, whereas there is none to start with. What other design pattern can I use to achieve my end goal ?

Would you recommend an alternative approach ?

2 Answers
Related