Skip to content
Advertisement

Kafka Stream-GlobalKTable join on a specific field

So I have a KStream that that gets deserialized into a POJO like so

JavaScript

And here’s how the Global Ktable record looks like

JavaScript

I want to be able to join the KStream’s stock_symbol field with the Ktable’s tckr field. Is this possible? I want to create a new EnrichedMessage object before I stream it into another topic. I had code like below but I seem to be getting some null pointer exceptions.

JavaScript

Here’s what the code snippet looks like.

JavaScript

I imagine that there might be some error in my leftJoin logic.

Advertisement

Answer

When doing a left join, you can assume that the left stream’s record is not null; however, you cannot assume that the right GlobalKTable will have a record for matching the given key, and therefore the resulting record could be null. In your case, when you instantiate a new EnrichedMessage(financialMessageValue, companySectorsValue), are you sure that companySectorsValue isn’t null? If it is null, are you handling it properly? It appears that your NPE is occurring in the constructor of EnrichedMessage, so just make sure that you know that companySectorsValue can be null.

Also, ensure your GlobalKTable is prepopulated before any join logic occurs.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement