Felix Angell
10/24/2023, 1:39 PMMarco Villalobos
10/24/2023, 5:15 PMMarco Villalobos
10/24/2023, 5:15 PMFelix Angell
10/26/2023, 1:23 PMMarco Villalobos
10/26/2023, 5:46 PMKeyedProcessFunction that is keyed by the unique key of whatever data that you're retrieving.
Use keyed state to store the data retrieved by key. If the keyed state is empty perform your database query with JDBC (you create a connection do the query and then disconnect) then store the data in keyed state. This is using keyed state as a cache.
The second more complicated approach, and the better solution in my opinion, is for your stream element to support multiple types of data, control data and stream data to control the stream job. It is briefly touched in this article: https://www.mux.com/blog/using-control-streams-to-manage-apache-flink-applications
The way you do that is instead of looking up the data with JDBC, you query your historical data and put it in your kafka source as control data. Key the data by its key, and store it in keyed state. When your data stream elements are processed, you can key the same key and then associate the data. In my code, I don't use a different topic, I just put both control data and stream data on the same kafka topic, and I encode it with Avro.
I hope you understand what I mean.